Results 1 to 3 of 3
  1. #1
    javaplus is offline Member
    Join Date
    Nov 2007
    Posts
    97
    Rep Power
    0

    Default when to use try...catch

    When coding, there are some statements that need try .. catch block otherwise complier gives error and forces the coder to write such statements under try ... catch block.

    How can I know, which statements should be written under try...catch block:confused:

    Currently, when complier gives error, I then put that statement under try...catch.

    Thanx.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    That seems to be the general practice - add the try-catch blocks where indicated by the compiler. The javadocs is/are the place to find out what is required, viz, the Method Detail section for the method(s) in question.

  3. #3
    ravian is offline Senior Member
    Join Date
    Nov 2007
    Posts
    115
    Rep Power
    0

    Default

    Thanks. Got the idea.

    I checked Java Docs and found following signature for FileOutStream constructor:

    Java Code:
    public FileOutputStream(File file)
                     throws FileNotFoundException
    which means we have to write in under try...catch block.

Similar Threads

  1. try catch!?
    By Joe2003 in forum Advanced Java
    Replies: 2
    Last Post: 01-28-2008, 08:51 PM
  2. Try Catch issue
    By curtis_fraser in forum Advanced Java
    Replies: 2
    Last Post: 12-14-2007, 12:04 AM
  3. Try Catch
    By Renegade85 in forum New To Java
    Replies: 4
    Last Post: 12-03-2007, 05:10 PM
  4. try...catch block
    By javaplus in forum New To Java
    Replies: 3
    Last Post: 11-06-2007, 08:53 PM
  5. Use try and catch
    By zoe in forum New To Java
    Replies: 2
    Last Post: 07-25-2007, 08:50 PM

Posting Permissions

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