You can make the exception an attribute

In a real Java try/catch, the catch argument is the exception object. But with web app error handling, remember, only officially-designated error pages get the exception object. To any other page, the exception just isn’t there. So this does not work:

Using the “var” attribute in <c:catch>
Use the optional var attribute if you want to access the exception after the end of the <c:catch> tag. It puts the exception object into the page scope, under the name you declare as the value of var.

Note
Flow control works in a <c:catch> the way it does in a try block—NOTHING runs inside the <c:catch> body after the exception.
In a regular Java try/catch, once the exception occurs, the code BELOW that point in the try block never executes—control jumps directly to the catch block. With the <c:catch> tag, once the exception occurs, two things happen:
If you used the optional “var” attribute, the exception object is assigned to it.
Flow jumps to below the body of the <c:catch> tag.

Be careful about this. If you want to use the “var” exception object, you must wait until ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access