You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Marcia Mendonca Cardador <ma...@summa-tech.com> on 2001/05/17 20:24:04 UTC

Displaying exception messages.

Hello,

     We are developing applications using Struts framework and EJBs. We
run into a problem regarding displaying exception messages and solved it
as follow.

    Any comments, suggestions or solutions :-) are highly welcome.

    Thanks and cheers,

    Márcia Cardador

    Summa Technologies Inc.
    www.summa-tech.com

--------------------------------------
Scenario:

    The middleware is Weblogic 5.1. We have two developmente teams: one
for JavaBeans and the other for JSP using Struts.

Problem:

    Let's say that a JSP developer mispelled a JavaBean property in the
Struts tag. Instead of having an exception with a nice message saying
so, Weblogic wraps the exception and send its own exception with a
generic message (for example: "Root cause of ServletException
javax.servlet.ServletException: runtime failure in custom tag 'form'").
The JSP developer usually gets no message in the page and she can not
figure out what is wrong from the message given at the Weblogic log. The
JavaBean developer also has to try to figure out what is wrong, because
it could be something in her program logic.

Partial Solution:

    We've changed the saveException method from ResquestUtils class to:

        public static void saveException(PageContext pageContext,
Throwable exception) {

           // added code to write exception to response
            try {

              ResponseUtils.write(pageContext, exception.getMessage()) ;

            } catch (Exception ex) {

              System.out.println("Exception in trying to write in
saveException() : " + ex.getMessage());

            }
           // end added code

            pageContext.setAttribute(Action.EXCEPTION_KEY, exception,
PageContext.REQUEST_SCOPE);
       }


    This change writes the nice exception messages to the generated HTML
page, so that the JSP developer can see it without any help from the
JavaBean developer.


Comments:

    This is not a complete solution because not all tags call
RequestUtils.saveException when an exception occurs. We still get the
generic message for some basic errors. But we could speed up our
development time a little bit.

    Futhermore, this solution was targeted to development phase and may
not be desirable when the application is in production.