Maybe I'll have to disappoint you about constructing a new Exception
class.
Did you have a look at
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/jsp/JspExcep
tion.html#JspException(java.lang.String,%20java.lang.Throwable) ? Looks
to me this does _exactly_ what you're trying to do.
However, I agree that Struts should not call new
JspException(e.getMessage()), but new JspException("Some intelligent
message", e); instead. This leaves the decision of what to display to
the programmer.
tomK
> -----Original Message-----
> From: Rick Hightower [mailto:[EMAIL PROTECTED]]
> Sent: vrijdag 16 november 2001 9:24
> To: Struts Developers List
> Subject: Exception handling --- suggestion for improvements
> ---- (e.g., template tag masks original exception) correction
> in sample code
>
>
>
> We have been using struts for a good while. We really dig the
> framework,
> but...
>
> Often times the struts tags catch the original exception (e.g.,
> ClassCastException), and then throw a JspException; thus, losing the
> original stack trace. This hides\masks the original
> exception. Hiding the
> orginal stack trace makes it harder to debug the problem.
>
> I wrote a JSPWrapperException that preserves the orginal
> stack trace for
> debugging.
> JSPWrapperException extends JspWrapper; however, like
> ServletException, it
> captures the original stack trace and displays it for
> debugging, i.e., the
> JSPWrapperException prints out the original stack trace of
> the original
> exception. This is a real boon for debugging.
>
> I modified 50 or so files in our copy of the struts code base (a 1.0
> derivative with some bug fixes and extra error handing) to use the
> JSPWrapperException instead of the JspException.
>
> It cost about an hour to make the changes, but I feel it will
> save us hours
> of debugging in the future.
>
> There is an ant build file with struts so making the changes
> and creating
> struts.jar was easy.
>
>
>
> I search the struts code base for code like this.... (example code)
>
> try{
> }
> catch(XYZException e){
> throw new JspException(e.getMessage());
> }
>
> to code that looks like this
> try{
> }
> catch(XYZException e){
> throw new JspWrapperException(e, e.getMessage());
> }
>
>
> BTW Here is the code for JspWrapperException....
>
> Enjoy.....
>
> /*
> * JspWrapperException.java
> *
> * Created on November 15, 2001, 11:14 PM
> */
>
> package org.apache.struts.util;
> import javax.servlet.jsp.JspException;
>
> /**
> *
> * @author rick
> */
> public class JspWrapperException extends JspException {
>
> Exception e;
>
> /**
> * @param Exception e
> * @param String message
> */
> public JspWrapperException(Exception e, String message) {
> super(message);
> this.e = e;
> }
>
> /**
> */
> public void printStackTrace () {
> super.printStackTrace();
> String sep = System.getProperty("line.separator", "\r\n");
> if (e != null) {
> System.err.println("--------------- extended Exception
> nest ----------- ");
> e.printStackTrace();
> }
> }
>
> /**
> * @param ps
> */
> public void printStackTrace (java.io.PrintStream ps) {
> super.printStackTrace(ps);
> String sep = System.getProperty("line.separator", "\r\n");
> if (e != null) {
> ps.println("--------------- extended Exception
> nest -----------
> ");
> e.printStackTrace(ps);
> }
> }
>
> /**
> * @param pw
> */
> public void printStackTrace (java.io.PrintWriter pw) {
> super.printStackTrace(pw);
> String sep = System.getProperty("line.separator", "\r\n");
> //
> //Nested exception
> if (e != null) {
> pw.println("--------------- extended Exception
> nest -----------
> ");
> e.printStackTrace(pw);
> }
> }
>
> /**
> * @return
> */
> public String getMessage () {
> StringBuffer message = new StringBuffer(150);
> message.append(super.getMessage());
>
> //
> //add Line separator
> String sep = System.getProperty("line.separator", "\r\n");
> message.append(sep);
>
> //
> //Add the nested exception
> if (e != null) {
> message.append(e.getMessage());
> //char = props["line.separator"]
> }
> return message.toString();
> }
> }
>
>
>
> Rick Hightower
> Director of Development
> eBlox, Inc.
>
> Check out our new website!
> www.eblox.com
>
> Contact Info:
> eBlox Tucson
> phone: 520-615-9345 x103
> fax: 520-529-5774
>
> Rick's stuff:
> http://www.eblox.com/people_detail.php?id=52
> http://www.geocities.com/rick_m_hightower/
> http://www.brainbench.com/transcript.jsp?pid=2351036
>
>
> --
> To unsubscribe, e-mail:
> <mailto:struts-dev-> [EMAIL PROTECTED]>
> For
> additional commands,
> e-mail: <mailto:[EMAIL PROTECTED]>
>
>
>
> --
> To unsubscribe, e-mail:
> <mailto:struts-dev-> [EMAIL PROTECTED]>
> For
> additional commands,
> e-mail: <mailto:[EMAIL PROTECTED]>
>
>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>