JSF custom page for unhandled exception not working

Newbie Source

I have followed several online materials to implement custom exception handler for my JSF application. I have added

<error-page>
    <location>/error.xhtml</location>
</error-page>

into my web.xml, and try it with the following code

FacesContext context = FacesContext.getCurrentInstance();
context.getExternalContext().responseSendError(400, "Testing 400 message");
context.responseComplete();

It works flawlessly with any kind of server error code. But it doesn't work for the unhandled exception such as RuntimeException. I try to throw an exception

throw new RuntimeException();

by a button clicked on UI, the exception is thrown, but it doesn't redirect to my custom error page /error.xhtml. What could be the reason? Did I missed any configuration? I have also tried to add

<error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/error.xhtml</location>
</error-page>

into web.xml but still not working. Any idea?

jsfexception-handlingjsf-2.2

Answers

comments powered by Disqus