Steps to write JavaScript Program:
1. Write a JavaScript function (Errorhandling) to handle the error.
2. Write onerror=Errorhandling; to pass the control whenever there is error.
Code to use onerror event:
<html>
<head>
<script type="text/javascript">
onerror=Errorhandling;
var My_Error="";
function Errorhandling(msg,url,l)
{
My_Error="Error Details:\n\n";
My_Error+="Error: " + msg + "\n";
My_Error+="URL: " + url + "\n";
My_Error+="Line: " + l + "\n\n";
document.write(My_Error);
}
function Click()
{
adddlert("Error Handling!");
}
</script>
</head>
<body>
<input type="button" value="Click" onclick="Click()" />
</body>
</html>
Output:
How to Run this program:
1. Copy the code above and paste to notepad file
2. Save file as SomeFileName.html (Please note that give file extension to .html or .htm)
3. Open this file in Internet explorer.
No comments:
Post a Comment