Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP Exception  RSS feed

 
Nathan Huiras
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering what the difference between these to chunks of code are:

catch(FinderException e)
{
throw new JspException("There was a problem looking up " + getCodeName () + ", " + getValue(), e);
}


catch(FinderException e)
{
throw new JspException("There was a problem looking up " + getCodeName() + ", " + getValue() + e.toString());
}

Is there a performance difference when you pass in one less argument, or are they the same thing?
 
Marilyn de Queiroz
Sheriff
Posts: 9079
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are the same. Java adds the toString() under the covers.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, they are not the same.

If you look closely you will see that the thrown exception is passed as the second parameter to the exception constructor in the first case. This records the exception as the root cause of the JspException -- which is much preferable to the second format which records no root cause and merely tacks the message of the exception to the message of the JspException. In this latter case, vital information regarding the root cause exception is lost.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the JSP forum...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!