This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JDBC and the fly likes Handling database exception Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Handling database exception" Watch "Handling database exception" New topic
Author

Handling database exception

Elly Kut
Greenhorn

Joined: Oct 06, 2007
Posts: 1
Hello Listers, I have a question about how to "design error handling" for a generic class that accesses a database.
I want to use try/catch/finally because if there is a problem during the flow, I would like to disconnect and destroy the connection (so that's why I don't want to declare a "throws")
But at the same time, after closing the connection in the finally clause, I also want my catch statement to throw an exception, so the calling application knows something bad happened. Should I create a custom exception class (extending SQLException) and throw it in my catch clause?
Thanks for your time.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56192
    
  13

"Elly K", please check your private messages for an important administrative matter.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32687
    
    4
What is more, you ought to have posted on the JDBC forum. Moving thread.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Handling database exception
 
Similar Threads
Confusion on Exception handling
Effects of pressing the Browser's Stop to the Servlet
throw/catch exception
How to correctly close the Connection object?
Finally abrupt return