Over a million developers have joined DZone.

Build a better Roo exception page

· Java Zone

Discover how powerful static code analysis and ergonomic design make development not only productive but also an enjoyable experience, brought to you in partnership with JetBrains

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="package.path.to.FullTraceMappingExceptionResolver"
<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!


From http://www.rimple.com/tech/2011/3/15/build-a-better-roo-exception-page.html

Learn more about Kotlin, a new programming language designed to solve problems that software developers face every day brought to you in partnership with JetBrains.


The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}