File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Handling database exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Handling database exception" Watch "Handling database exception" New topic

Handling database exception

Elly Kut

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

Joined: Jan 10, 2002
Posts: 63866

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

[Asking smart questions] [About Bear] [Books by Bear]
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46402
What is more, you ought to have posted on the JDBC forum. Moving thread.
I agree. Here's the link:
subject: Handling database exception
It's not a secret anymore!