11.5. Handling Exceptions with the TryCatchFinally Interface

In JSP 1.1, you can trap exceptions that occur in each of your tag handling methods (doStartTag, doEndTag, etc.). But, what happens if an exception occurs during the processing of the body of the tag? What if you want to respond to exceptions in doStartTag, doEndTag, and doAfterBody the same way and don’t want to repeat your code?

JSP 1.2 answers these questions by providing a new interface called TryCatchFinally with two methods:

  • doCatch(Throwable t)

  • doFinally()

If your tag implements this interface and an exception occurs during any of the tag life-cycle methods or during the processing of the tag body, the system calls the doCatch method. Regardless of whether an exception occurs, ...

Get More Servlets and JavaServer Pages™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.