You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by Apache Wiki <wi...@apache.org> on 2006/06/21 08:19:05 UTC

[Myfaces Wiki] Update of "Handling Server Errors" by MarioIvankovits

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Myfaces Wiki" for change notification.

The following page has been changed by MarioIvankovits:
http://wiki.apache.org/myfaces/Handling_Server_Errors

------------------------------------------------------------------------------
  
  }}}
  
+ Also have a look at our ExceptionUtils class. It encapsulates the way how to get the real root cause
+ 
+ {{{
+ 	[1] List exceptions = ExceptionUtils.getExceptions(exception);
+ 	[2] Throwable throwable = (Throwable) exceptions.get(exceptions.size()-1);
+ 	[3] String exceptionMessage = ExceptionUtils.getExceptionMessage(exceptions);
+ }}}
+ 
+ [1] get a list of all exceptions - using getRootCause if available or getCause
+ [2] get the initial exception
+ [3] get the first exception with an message starting with the initial exception
+ 
+ So the new fillStackTrace become
+ {{{
+     private void fillStackTrace(Throwable ex, PrintWriter pw)
+     {
+         if (null == ex) {
+             return;
+         }
+ 
+ 	List exceptions = ExceptionUtils.getExceptions(exception);
+ 	Throwable throwable = (Throwable) exceptions.get(exceptions.size()-1);
+ 
+         for (int i = 0; i<execptions.size(); i++)
+         {
+             if (i > 0)
+             {
+                 pw.println("Cause:");
+             }
+             throwable.printStackTrace(pw);
+         }
+     }
+ }}}
+ 
  In the backing bean we construct a message which informs the user that something we didnt't plan for has happened with directions on who to call, what to do etc. We don't really care if they actually do cut-and-paste the error and email it to us as it is also in Tomcat's logs but giving the user something to do and become part of resolving the problem is always a good idea :)
  
+ 
+ == with plain JSP error page ==
+ 
+ If you didn't require any JSF functionality in your JSP page it might be worth to consider using the following error.jsp
+ 
+ [http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/examples/simple/src/main/webapp/error.jsp?view=markup]
+ 
+ with this web.xml configuration
+ 
+ {{{
+ 	<error-page>
+ 		<error-code>500</error-code>
+ 		<location>/error.jsp</location>
+ 	</error-page>
+ }}}
+ 
+ This reduces the number of technologies required to show the error page which might improve the availablity of this page ;-)
+