Onerror event in Java script
We can detect java script errors by using the following handleErr function. This function will give the error message, url and line number. so that we can easily troubleshoot that error.
Example :
<html>
<head>
<script type=”text/javascript”>
onerror=handleErr
var txt=”"
function handleErr(msg,url,l)
{
txt=”There was an error on this page.\n\n”
txt+=”Error: ” + msg + “\n”
txt+=”URL: ” + url + “\n”
txt+=”Line: ” + l + “\n\n”
txt+=”Click OK to continue.\n\n”
alert(txt)
return true
}
function callfn()
{
adddlert(”Welcome user”)
}
</script>
</head>
<body>
<input type=”button” value=”View alert” onclick=”callfn()” />
</body>
</html>
