aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "exception" Watch "exception" New topic
Author

exception

Sridhar Srinivasan
Ranch Hand

Joined: Nov 07, 2003
Posts: 117
can anybody please explain the reason for the compile time erro while compiling the following code.Thanks


[ May 25, 2004: Message edited by: Barry Gaunt ]

Software_guy
Baps Vakkalagadda
Ranch Hand

Joined: May 25, 2004
Posts: 47
Inner try/catch block is never executed because you are forcing to throw an exception (throw new Level1Exception();) before the inner try/catch block. JVM does not like these kind of situations in the code.
Baps Vakkalagadda
Ranch Hand

Joined: May 25, 2004
Posts: 47
Let me change my statement little bit:

Inner try/catch block is never executed because you are, unconditionally, forcing to throw an exception (throw new Level1Exception();) before the inner try/catch block. JVM does not like these kind of situations in the code.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Exactly which compile time error are you writing about?


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Baps Vakkalagadda
Ranch Hand

Joined: May 25, 2004
Posts: 47
The one and only error that JVM complains (with the above code) is 'unreachable statement' pointing the inner 'try' statement.

If entire outer try/catch block (including outer exception handling) is commented or removed, then we get 'unreported exception Level1Exception'.
Sivakumar Swaminathan
Greenhorn

Joined: May 26, 2004
Posts: 7
The code is unreachable because since in the previous line you are throwing an exception, the try block can never be reached when the program runs.That is why it complains that the code is unreachable.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: exception