Chariot Training Classes

Training Courses

I run Chariot's training and mentoring services. We provide training in AngularJS, HTML5, Spring, Hibernate, Maven, Scala, and more.

Chariot Education Services


Chariot Emerging Tech

Learn about upcoming technologies and trends from my colleagues at Chariot Solutions.


Chariot Conferences


« It's a comin' - Philly Emerging Tech | Main | Adding deeper logging to Webflow Exceptions »

Build a better Roo exception page

Ok, Roo fans. This is a quick post, in response to a forum post on the Manning Roo in Action forum. Wanna get Root Causes in your exceptions page? Do this!

Build an Exception Resolver

Start by building a class that extends SimpleMappingExceptionResolver. This example uses the Apache commons-lang utility class, ExceptionUtils, to get the root cause exception and push it to the page. I suspect I may need to check for nulls here so if you get a chance to debug this before me, post a message and I'll update the blog post:

public class FullTraceMappingExceptionResolver extends
  SimpleMappingExceptionResolver {

  protected ModelAndView getModelAndView(String viewName, Exception ex) {
    ModelAndView modelAndView =  super.getModelAndView(viewName, ex);
    String stackTrace = ExceptionUtils.getFullStackTrace(ExceptionUtils.getRootCause(ex));
    modelAndView.addObject("rootCause", stackTrace);
    return modelAndView;

Add commons-lang 2.5

Add this to your pom.xml file, in the dependencies section... A Roo shell command can do this for you, but here is the fragment:


Install it!

Next, install it in the webmvc-config.xml file, by replacing the mounted class SimpleMappingExceptionResolver with the FullTraceMappingExceptionResolver.  Just swap the value in the class property below and leave the rest alone:

<bean class=""
  <property name="exceptionMappings">
      <prop key=".DataAccessException">dataAccessFailure</prop>
      <prop key=".NoSuchRequestHandlingMethodException">resourceNotFound</prop>
      <prop key=".TypeMismatchException">resourceNotFound</prop>
      <prop key=".MissingServletRequestParameterException">resourceNotFound</prop>

Modify unhandledException.jspx

Ok, the final step - just add the unhandled exception to the jspx for the uncaught exceptions, WEB-INF/views/uncaughtException.jspx:

<c:if test="${not empty rootCause}">
  <util:panel id="_fullStackTrace" 
        title="Full Stack Trace" openPane="false">
    <h4>Full Stack Trace</h4>
    <div style="overflow: auto;" 
      <pre><c:out value="${rootCause}"/></pre>

Want more Roo in Action goodness? Subscribe to the MEAP!

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>