java
package coreservlets;
/** Exception used to flag particularly onerous
programmer blunders. Used to illustrate the
exception-type web.xml element.
*/
public class DumbDeveloperException extends Exception {
public DumbDeveloperException() {
super("Duh. What was I *thinking*?");
}
Chapter 2 ?– Controlling Web Application Behavior with web.xml 76
public static int dangerousComputation(int n)
throws DumbDeveloperException {
if (n < 5) {
return(n + 10);
} else {
throw(new DumbDeveloperException());
}
}
}
Listing 2.20 RiskyPage.jsp
Risky JSP PageRisky Calculations
<%@ page import="coreservlets.*" %>
<% int n = ((int)(10 * Math.random())); %>
- n: <%= n %>
- dangerousComputation(n):
<%= DumbDeveloperException.dangerousComputation(n) %>
Listing 2.21 DDE.jsp
DumbDumb Developer
We're brain dead. Consider using our competitors.
Listing 2.19 DumbDeveloperException.java (continued)
2.9 Designating Pages to Handle Errors 77
Figure 2??“20 Fortuitous results of RiskyPage.jsp.
Figure 2??“21 Unlucky results of RiskyPage.jsp.
Listing 2.22 web.xml (Excerpt designating error pages for exceptions)
Pages:
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116