JavaScript syntax: | - | function anErrorHandler(aMessage, aURL, aLine) { someCode }; |
Argument list: | aLine | The line number where the error occurred |
aMessage | The text of the error message | |
anErrorHandler | An identifier name for the function | |
aURL | The URL of the document containing the error | |
someCode | The script source for the error handler |
This is a means of trapping the errors in any script. You can activate an error handler in various ways. Placing this line at the top of your script will trap all errors within that script:
self.onerror = function() { return true };
Because the script always returns true, no error dialog will ever be displayed.
Here is a pseudo-code example of a better technique.
function HandleErrors(aMessage, aURL, aLine) { //If we can handle the error with a piece of code return true; //Else we can't do anything return false; } self.onerror = HandleErrors;
An error handler should return true if the host environment can safely ignore the error and false if the environment needs to handle the error as normal.
See also: | Error, Error events, Semantic event, Window.onerror |
Prev | Home | Next |
Error events | Up | Error handling |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |