Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Empty catch statement in JDBC code

 
Justin Chu
Ranch Hand
Posts: 209
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34410
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic