This sample demonstrates the use of the onerror event to trap run-time script errors. When you click the Throw Error button, the line of script specified in the text field is evaluated. The onerror event fires when the invalid script entry is evaluated, and the results are posted at the bottom of the page.
You can change the values of the script to see how this sample works. For example, a valid script entry that sets the background color to blue is document.body.style.backgroundColor="#0000FF". Evaluating this line of code does not throw an error because the syntax and values are correct. However, specifying a line of script such as someObject.someProperty=true does throw an error because there is no object named someObject in this sample that exposes a property named someProperty.
If you have a script debugger installed, you might need to disable script debugging in Internet Explorer (Tools, Internet Options, Advanced) before the onerror event will fire.
[Right-click and choose View Source from the shortcut menu.]
© 2007 Microsoft Corporation. All rights reserved. Terms of use.