Exception Handling

Tapestry handles exceptions that are thrown during the processing of any request. Exceptions are caught when they occur and result in the generation of a page with all the details. Of course, in your own application, such exceptions will never occur, or will be caught and handled by your own code.

Still, it's nice that Tapestry can assist when debugging during development, when uncaught exceptions may in fact be thrown.

To demonstrate what Tapestry does for exceptions, we need to do a little bit of sneaky work.

First, start up the adder application and enter a few numbers:

Figure 6.2. Adder application before error

Now, edit the URL in the Address field, and change the word "action" to "acion" (i.e, remove the letter 't') and hit return.

Figure 6.3. Error in Adder application

Tapestry has discovered that the URL was invalid ... in this case that the word "action" was changed to "acion". Since Tapestry normally produces all the URLs it must later interpret, it doesn't make an effort to pretty this up (as it does with stale links and sessions), instead it throws an exception which is caught and displayed.

As you may notice, the exception report is extremely complex. Tapestry displays all the information it can about the exception that was thrown ... it can even break apart nested exceptions and dig down to the deepest one. It shows the stack trace where the deepest exception was thrown. It also provides information about the HttpServletRequest, HttpSession, ServletContext and Java VM.

Finally, it includes a link that will restart the application from scratch, invaliding the current HttpSession and creating a new one as necessary.