Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

On Exception Handling

 
Karthik Balasubramanian
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we throw an exception from "Catch" and "Finally" block?
Thanks,
Karthik
 
Shiva Mantri
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes you can, but you will lose the exception information thrown from try clause, unless you log the exception information.

JLS11.3 Handling of an exception
If a try or catch block in a try-finally or try-catch-finally statement completes abruptly, then the finally clause is executed during propagation of the exception, even if no matching catch clause is ultimately found. If a finally clause is executed because of abrupt completion of a try block and the finally clause itself completes abruptly, then the reason for the abrupt completion of the try block is discarded and the new reason for abrupt completion is propagated from there.

[ January 28, 2003: Message edited by: Shiva Mantri ]
 
Sarma Lolla
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although in real world projects you rarely use the finally block, it is very common to catch one exception and throw another exception from the catch clause.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic