<HTML>
<HEAD>
<TITLE>Creating a Custom Exception Object</TITLE>
</HEAD>
<BODY>
<H1>Creating a Custom Exception Object</H1>
<%!
class MyException extends Exception
{
int value;
public String toString()
{
return "MyException " + value;
}
MyException(int v)
{
value = v;
}
}
void doWork(int value) throws MyException
{
if(value == 0){
throw new MyException(value);
}
}
%>
<%
try {
doWork(3);
doWork(2);
doWork(1);
doWork(0);
}
catch (MyException e) {
out.println("Exception: " + e);
}
%>
</BODY>
</HTML>
|