Hugh Lee Hugh Lee - 3 months ago 25
Java Question

Can I throw exception in JSTL?

I'm making some JSP tag. I pass a type parameter to the tag.

The code look like this:

<%@ attribute name="type" require="true" %>
<c:when test="${type eq 'even'}">
<c:set var="remainder" value="0" />
<c:when test="${type eq 'odd'}">
<c:set var="remainder" value="1" />
<%-- Want to throw exception!! --%>

I want to throw an exception if I pass a wrong value. When I searched about this subject I just found this. Can't I throw a normal exception in JSTL?


Just throw to notice the problem immediately

Who would "notice" ? That exception can only be caught by the container and it will result in some "500 Internal Server Error" page (or some custom error page you define).

If that's what you really want, you can define a custom tag that will just perform "throw new WhateverException()", and then make use of your custom taglib like: <mytaglib:reportError/>, as the standard core taglib did not consider throwing an exception would ever be desirable for anyone.