dev@glassfish.java.net

Re: Exception class names in error messages

From: Byron Nevins <byron.nevins_at_oracle.com>
Date: Mon, 20 Sep 2010 10:39:58 -0700

  A line or two of code will fix it for all cases simultaneously. Have
the ctor for CommandException do it automatically. I've also noticed
the following problem -- a lot


try {

         //some code that might throw A
}
catch(Exception e) {
       throw new A(e);
}

--> I.e. an A might be wrapped inside an A. Instead do this:

catch(A e) {
       throw e;
}
catch(Exception e) {
       throw new A(e);
}

On 9/17/2010 11:27 AM, Tom Mueller wrote:
> 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
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>

-- 
Byron Nevins  -  Oracle Corporation
Home: 650-359-1290
Cell: 650-784-4123
Sierra: 209-295-2188