This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Exception throwing  RSS feed

 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This is from an Enthuware question:



When I run the code I get:

Exception in thread "main" java.lang.CloneNotSupportedException
at Main.m1(Main.java:24)
at Main.main(Main.java:9)


So an SQLException should be thrown from within the catch block, but since the finally block is always executed a CloneNotSupportedException is thrown as well.
My question is what happens to the SQLException?

Handling just the CloneNotSupportedException when calling m1() compiles fine:



Running this code just results in the output "CloneNotSupportedException".
It seems like an SQLException is thrown in the catch block but never handled or declared.

Thanks,

John
 
Saloon Keeper
Posts: 9123
172
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The exception thrown in the try block is simply ignored and "overruled" by the exception thrown in the finally block.

This is the reason why finally blocks should never terminate abnormally. Whenever you have a checked exception in a finally block, catch it and log it. This way, you will get a notification in your log file why the finally block failed, and the exception in the try block will propagate normally.
 
John Stark
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good idea. Thanks Stephan.

John
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!