The Artima Developer Community
Sponsored Link

Java Buzz Forum
Avoid empty catch blocks

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Ben Hosking

Posts: 208
Nickname: hoskinator
Registered: Apr, 2006

Ben Hosking is Java Developer with about 5 years experience and interest in OO
Avoid empty catch blocks Posted: May 30, 2006 6:37 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Ben Hosking.
Original Post: Avoid empty catch blocks
Feed Title: A Funny Java Flavoured Look at the World
Feed URL: http://businesslogs.com/WebLog/RSS.xml
Feed Description: The blog looks at using Java and programming in general as it pops up in life as a Java programmer. It will have links to interesting Java articles and resources. It will also have a lot of SCJP Java 1.5 information and links as I am currently studying
Latest Java Buzz Posts
Latest Java Buzz Posts by Ben Hosking
Latest Posts From A Funny Java Flavoured Look at the World

Advertisement

When I was writing code under a very harsh deadline and there was smoke coming off the keyboard, I had left a few exceptions just being caught but without doing anything in them.

This is a really bad state of affairs and it's certainly not something I am proud of. I have been going back through today and deciding what I should do in some of these errors.

In most cases I am just logging out the error message with some information (like class name, method name and additional information). This might not seem that good but it's a whole lot better than having nothing in the catch block and at least you can get the customer to turn on the logger and read out the message to you.

I recently have been the beneficiary of this, I had a problem whilst installing the software at a customers site and turned on the login and although I didn't have a clue what was causing the problem, at least we knew where to look because we logged out the error message with a e.getMessage with the class name and method name in front of it.

Whilst feeling in the exception blocks, I thought how lucky I was that the code (thanks to some unit tests) worked but if it hadn't then I would have had a clue because there would have been no error messages in the log files to look at.

I have vowed not to let this sloppy coding practice continue, it would have only taken me a few minutes when writing the code. It can be easy to do this no code in the catch blocks because they are auto generated by eclipse but don't fall into the trap.

I think I am going to try and get eclipse to fill in the necessary code for me, so I won't forget, now that would be nice.

Read: Avoid empty catch blocks

Topic: Speed up JUnit tests in Ant Previous Topic   Next Topic Topic: links for 2006-05-19

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use