Results 1 to 7 of 7
  1. #1
    NoobieCode is offline Senior Member
    Join Date
    Mar 2013
    Posts
    123
    Rep Power
    0

    Default exception handling

    Can someone show me a basic skeleton of a try catch for a division method using I/O object. It can't divided by 0, string, and real numbers (decimals)

  2. #2
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,725
    Rep Power
    5

    Default Re: exception handling

    What is an I/O object?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default Re: exception handling

    Java Code:
    try {
      // do something
    } catch (SomeException e) {
      // do something
    }

  4. #4
    NoobieCode is offline Senior Member
    Join Date
    Mar 2013
    Posts
    123
    Rep Power
    0

    Default Re: exception handling

    so the user provides in input. And inorder to read an input, I have to create or instantiate some I/O class objects to help with the try catch block. I dunno how to do that

  5. #5
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,725
    Rep Power
    5

    Default Re: exception handling

    That's alright! But you have to go learn. Try typing "java io" into Google and see what you get.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    NoobieCode is offline Senior Member
    Join Date
    Mar 2013
    Posts
    123
    Rep Power
    0

    Default Re: exception handling

    Do i create a File object that stores the user input, Use fileInputStream and then try catch that?

  7. #7
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,725
    Rep Power
    5

    Default Re: exception handling

    A File does not contain anything; it is purely to provide information about a file or directory on disc (size, if it exists or not, if you can read or write to it, etc).

    If you want to write user input to a file, you use an OutputStream, or in the case of text data it could be a FileWriter or a PrintStream. And yes using a FileInputStream or a form of a Reader (FileReader, BufferedReader) you can read data back. As the links you can find using the google search I mentioned can teach you. You may be yet another person with Google Phobia, so I'll just post the link directly that you should have found in less than 3 seconds of effort yourself:

    Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Exception Handling
    By teja in forum New To Java
    Replies: 6
    Last Post: 05-15-2013, 06:41 PM
  2. exception handling
    By NoobieCode in forum New To Java
    Replies: 6
    Last Post: 05-15-2013, 12:54 PM
  3. exception handling
    By Elaforestis in forum New To Java
    Replies: 1
    Last Post: 01-29-2013, 04:37 AM
  4. Exception handling
    By Moedig in forum New To Java
    Replies: 2
    Last Post: 11-10-2011, 10:43 PM
  5. Exception Handling
    By link6790 in forum New To Java
    Replies: 16
    Last Post: 05-19-2011, 06:57 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •