I’m catching all exceptions within:
java.lang.Throwable
/page.xhtml
java.lang.Error
/page.xhtml
But what If I get eg a hibernate ex:
org.hibernate.exception.ConstraintViolationException
Do I have to define error-pages for EVERY maybe occuring exception? Can’t I just say “catch every exception”?
Update
Redirect on a 404 works. But on a throwable does not!
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error.xhtml</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/error.xhtml</location>
</error-page>
The
java.lang.Throwableclass is the least common ancestor of all classes in the Java exception class hierarchy. All exception and error classes extendThrowable, directly or indirectly.If you have an error page for
Throwable, any exception that doesn’t have a more specific error page will end up there.Therefore, the answer to your question is “No”. You can handle Hibernate exceptions separately if you want to (at any granularity you think is appropriate), but you don’t have to.
UPDATE
There are a number of possible reasons why the exceptions are not producing error pages. For example, they might be occurring during redirect processing or they might be caught by a filter. Or they might be thrown after the response header has been committed; e.g. if the exception occurs during the formatting of the response HTML.
(One salient clue will be whether you are getting any error page at all when an exception is thrown. If you are getting a ‘500’ error page then something is happening. If not then you are probably in one of those situations which prevent any error page generation.)
Anyway, here is what the Servlet spec (version 3.0) says. Read it carefully.
10.9.2 Error Pages