Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

try catch exception handling

 
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have encountered some code where an exception is thrown in the try{} block, is caught and is in the process of being handled by the catch{} block when another exception occurs.
In this code, once the second exception occurs in the catch{} block, it proceeds directly to the finally{} block (of the first exception) with no indication that a second exception ever occurred.
I was only able to deduce what was happening by stepping thru the code with a debugger.
My questions are:
1) Is this correct exception handling behavior?
2) Should a second exception be thrown?
3) And, if a second exception should be thrown, should the finally{} block for the first exception be executed?
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You would need to handle the exception being thrown in the catch block with its own try/catch block, and do what you want to, before the execution is transfered to the finally block.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) yes
2) yes
3) yes
 
You totally ruined the moon. You're gonna hafta pay for that you know. This tiny ad agrees:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic