0

How do I create a custom Exception and handle it in web.xml with the error-page tag direct it to a specific page.

I have tried to create a exception extends the servlet exception like this.

public class MyException extends ServletException {

    private static final long serialVersionUID = 1L;

    private String[] errArray;

    public MyException (String[] errArray){
    this.errArray = errArray;
    }

    public String[] getErrors(){
        return errArray;
    }
}

Then I put this inside web.xml

<error-page>
    <exception-type>my pach to the exception.MyException </exception-type>
    <location>/web_service_errorr.jsp</location>
</error-page>

And I tried to throw this in the project. Then the exception still we be catch by

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

At the beginning of the error message it is javax.servlet.ServletException, but it has something like Root cause my MyException in the message.

If am not doing it right, how should I catch a custom exception and redirect it to a jsp page?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Tech Noob
  • 510
  • 1
  • 9
  • 33
  • The `` is in invalid syntax. But I guess that you carelessly oversimplified/obfuscated it without realizing that you're introducing a new cause of your own problem. Please copypaste **real** code without editing it. You can always rename the package to `com.example` or so, but you need to make sure that you have **actually tested** that as well. – BalusC Aug 08 '13 at 13:08
  • Thank you, I just edited the `` when I post it here. In the project it does display a link to that class. I was just trying to hide the package names here. Is there any problem with my implementation please? – Tech Noob Aug 08 '13 at 13:27

0 Answers0