GeeCON Prague 2014*
The moose likes JDBC and the fly likes Empty catch statement in JDBC code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "Empty catch statement in JDBC code" Watch "Empty catch statement in JDBC code" New topic
Author

Empty catch statement in JDBC code

Justin Chu
Ranch Hand

Joined: Apr 19, 2002
Posts: 209
    
    1
In general (probably universally), it is bad practice to have empty catch blocks. But what do you think of the empty catch statements in the finally block of the below code?

If this is bad design, what's the best way to do it without writing 10 lines of wrapper code around 3 lines of real JDBC statement.

Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30586
    
154

Originally posted by Chu Tan:
In general (probably universally), it is bad practice to have empty catch blocks. But what do you think of the empty catch statements in the finally block of the below code?

That's fine. There is no expected behavior on failure closing resources. Some people log it or put an //ignore comment so future readers of the code don't think you forgot. Another idea is to put the common close code in a utility class so you only have the empty try/catch logic in one place.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
GeeCON Prague 2014
 
subject: Empty catch statement in JDBC code