• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exception Handling

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



Options are...

A. An exception is thrown and the exception message thrown from first catch is diplayed with the exception stack trace.
B. An exception is thrown and the exception message thrown from second catch is diplayed with the exception stack trace.
C. Prints nothing.

D. Compilation error.

E. Prints i=? where ? stands for the generated random value.

ANSWER

Surprisingly ...the answer is C

Error stack trace is not thrown because of finally
I guess it should atleast throw exception...

Pls throw some insight if my understanding is wrong
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friend,

In catch Block if any exceptions are raised again or it return call to the called method. Before handling the exception or before returning value it will execute finally block.

But in case finally block there is no control transfers like this. you returned value of type void. If you have any return statements or System.exit()in finally block,if any exception raising and return statements are present in catch block, then they were discarded.

Regards
Krishna.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since the finally block of a try-catch-finally clause is always executed, even if a break or return statement is executed in the try block, the finally block can actually override the request to break or return.

The finally block can decide not to break or return or even change the return value by executing its own return statement.

here return statement in finally overrides return statemetn of catch block
 
reply
    Bookmark Topic Watch Topic
  • New Topic