• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

exception

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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'.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Well behaved women rarely make history - Eleanor Roosevelt. tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic