function TryCatch(x)
{
try
{
try
{
if (x == 0) // Evalute argument.
throw "x equals zero"; // Throw an error.
else
throw "x does not equal zero"; // Throw a different error.
}
catch(e)
{
// Handle "x = 0" errors here.
if (e == "x equals zero") // Check for an error handled here.
return(e + " handled locally."); // Return object error message.
else // Can't handle error here.
throw e; // Rethrow the error for next
} // error handler.
}
catch(e)
{ // Handle other errors here.
return(e + " handled higher up."); // Return error message.
}
}
document.write(TryCatch(0));
document.write(TryCatch(1));
|