HOWTO: Trap JScript Errors on a Web PageID: Q183616
|
There is currently no language support for error handling in JScript. However, when using JScript in a Web page, there is a window.onerror() event, which you can use to trap errors and handle them as you wish.
The following HTML demonstrates how to use the onerror event of the window
object to trap an error in JScript code:
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE>Window onerror event with JScript</TITLE>
</HEAD>
<script language=JavaScript>
function errorHandler(message, url, lineno)
{
alert("oops: message");
return true;
}
window.onerror = errorHandler;
new ActiveXObject("Non-existing");
</script>
<BODY>
<P>This page will generate a scripting error while loading (you should see an alert box instead of the standard script error message).</P>
</BODY>
</HTML>
For information on using JScript, refer to the documentation available at the following Web site:
http://msdn.microsoft.com/scripting/
Additional query words:
Keywords : kbcode kbIE300 kbIE301 kbIE400 kbIE401 kbJScript100 kbJScript200 kbJScript300 kbIE302 kbIE500
Version : WINDOWS:1.0,2.0,3.0,3.01,3.02,4.0,4.01
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: May 3, 1999