Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Handling database exception

 
Elly Kut
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65658
129
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Elly K", please check your private messages for an important administrative matter.
 
Campbell Ritchie
Marshal
Posts: 53110
124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is more, you ought to have posted on the JDBC forum. Moving thread.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!