• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

exception

 
Sridhar Srinivasan
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Baps Vakkalagadda
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly which compile time error are you writing about?
 
Baps Vakkalagadda
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic