Reputation: 33
ı want to add a errorPage my project. When to be excaption ı want to open errorPage. For example;
try {
if ("Plus".equals(op)) {
v1 = getNumber(value1);
v2 = getNumber(value2);
result = String.valueOf(v1 + v2);
} else if ("Minus".equals(op)){
v1 = getNumber(value1);
v2 = getNumber(value2);
result = String.valueOf(v1 - v2);
} else{
result = value1+value2;}
} catch (NumberFormatException oops) {
Exception e = new RuntimeException(oops);
log("*-*-*-*** Bad news - validation failed or has been bypassed*-*-*-*-*", e);
oops.printStackTrace();
}
request.setAttribute("result", result);
RequestDispatcher dispatcher = request.getRequestDispatcher("RequestDispatcher.jsp");
I use this code in xml file but doesnt work
<error-page>
<!-- <exception-type>java.lang.NumberFormatException</exception-type> -->
<exception-type>java.lang.NumberFormatException</exception-type>
<location>/WEB-INF/BadNumber.jsp</location>
</error-page>
my error message is : For input string : "s"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
Any help would be appreciated.
Upvotes: 1
Views: 48
Reputation: 1651
Your error page is not working because you are catching the exception without rethrowing it again. If you want to catch the exception manually in your code you have to make sure that it will be rethrown again (use exactly the same type as you specified in your Error Page under <exception-type>
)
Upvotes: 3