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