O'Reilly logo

Java Garage by Eben Hewitt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exception Handling Pretty Good Practices

This is a list of things that are a good idea to do when writing code in the real world (he writes, as if there is any other world). I don't know if they are the best practices ever. That's pretty hard to determine concretely.

  • Do not squash exceptions—do something useful with them. It is common to see code that catches an exception, and then does nothing. The following will compile:

    ...catch(Exception e) {}.
    

    Usually it isn't quite that angry, and you see a call to System.out.println(). If your application is a console application, this might be appropriate, but would it be better to save that message to a log file along with a timestamp, class name, and username? You bet. If you are writing a desktop ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required