Sunday, December 14, 2014



Preferred Error Handling Technique


function myErrorHandling()
{
// put in code that generates an error
// change this code to throw various error types
// and see how the errors are being captured
try
{
throw new URIError("This is a URIError thrown...");

// throw new RangeError("This is a RangeError thrown...");
// throw new TypeError("This is a TypeError thrown...");
// throw new SyntaxError("This is a SyntaxError thrown...");
// throw new Error("This is a Custom Error thrown...");
}
catch(err)
{
switch(err.name)
{
case "URIError":
alert(err.name + " || " + err.message);
break;
case "RangeError":
alert(err.name + " || " + err.message);
case "TypeError":
alert(err.name + " || " + err.message);
break;
case "SyntaxError":
alert(err.name + " || " + err.message);
break;
case "CustomError":
alert(err.name + " || " + err.message);
break;
}
}
finally
{
alert("This block executes at all times");
}
}

No comments:

Post a Comment