dev@glassfish.java.net

Exception class names in error messages

From: Tom Mueller <tom.mueller_at_oracle.com>
Date: Fri, 17 Sep 2010 13:27:31 -0500

  This might be obvious to you, but I thought I would share this anyway.

Some of our command generate error message output that has the name of
the exception class in the error message.
One way that these class names can creep into the messages is doing the
following:

try {
     ...
}
catch (SomeException se) {
     ... do something
     throw new CommandException(se);
}

The problem here is the CommandException constructor that takes a
Throwable results in the message for the CommandException being the name
of the exception class (SomeException), a ":", and the message from the
exception.

To eliminate the exception class name in the message, one can use this
instead:

     throw new CommandException(se.getMessage(), se);

Hope this is useful.
Tom