Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JDBC and Relational Databases 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


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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: 32636
    
216

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.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Empty catch statement in JDBC code
 
It's not a secret anymore!