Results 1 to 4 of 4
Like Tree3Likes
  • 1 Post By mine0926
  • 2 Post By JosAH

Thread: Try... Catch?

  1. #1
    Callofdudey is offline Member
    Join Date
    Sep 2011
    Posts
    10
    Rep Power
    0

    Default Try... Catch?

    Consider this block of code:

    Try {

    Divide d = new Divide;
    int result = d.div (5,0);

    }

    Catch (Exception e )
    {
    System.out.println ( e.getMessage( ) );
    }

    In this code, 10 will be divided by 0, which will surely yield an error.

    My question would be:
    1,
    What is the "e" in the parenthesis that following the Catch keyword?

    2, Just WHAT error would be passed to WHOM?
    Will the error-dealing mechanism actually know what error it is in some more complicated situation, e.g. reading a file, then there won't be just one error, there could be disk suddenly removed, other program is using that file, no such file etc etc.

    To rephrase my 2nd cluster of question and make it clearer:

    Does the catch key word actually enables a mechanism that try to deal with a detailed error, or it just deal with an error, it doesn't care what it is?

    If it does deal with a detailed one, how?


    Posting tutorial links is also welcomed.

  2. #2
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default Re: Try... Catch?

    You might want to read this: Lesson: Exceptions (The Java™ Tutorials > Essential Classes)
    And for future reference, bookmark this The Really Big Index
    sunde887 likes this.

  3. #3
    Nikhilkumr is offline Member
    Join Date
    Oct 2010
    Location
    Nagpur
    Posts
    6
    Rep Power
    0

    Default Re: Try... Catch?

    how to write?
    please help me.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default Re: Try... Catch?

    Quote Originally Posted by Nikhilkumr View Post
    how to write?
    please help me.
    First locate a pen or pencil. A pen or pencil is a pointy cylindrical shaped device. Put the pen or pencil between your thumb and index finger; keep the pointy side downwards because if you keep the pointy side in an upward position (while holding the pen or pencil between your thumb and index finger) and you have to sneeze, the consequences may be horrible. Put a piece of paper in a horizontal position, just underneath the pointy side of the pen or pencil. A table is an ideal support for this configuration. Now start moving your hand (the one holding the pen or pencil) in a slow motion from left to right while you make littly wiggly movements with your thumb and index finger. When the pointy side of the pen or pencil is going to scratch the surface of the table, move your hand (and pen or pencil) to the left side of the paper again.

    Glad to have helped.

    kind regards,

    Jos
    Last edited by JosAH; 10-06-2011 at 09:38 PM.
    Tolls and Lucas_F98 like this.
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. try and catch
    By Bimz in forum New To Java
    Replies: 1
    Last Post: 09-26-2011, 09:44 AM
  2. try catch help
    By vividcooper in forum New To Java
    Replies: 8
    Last Post: 02-11-2010, 09:00 AM
  3. how to catch two exceptions in one catch()?
    By arnab321 in forum New To Java
    Replies: 1
    Last Post: 11-06-2008, 10:54 AM
  4. try catch...
    By MarkWilson in forum New To Java
    Replies: 8
    Last Post: 06-27-2008, 05:39 PM
  5. Use try and catch
    By zoe in forum New To Java
    Replies: 2
    Last Post: 07-25-2007, 07: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
  •