Error handler (Interface)

Triggered by an error in the JavaScript execution.

JavaScript syntax:-function anErrorHandler(aMessage, aURL, aLine) { someCode };
Argument list:aLineThe line number where the error occurred
aMessageThe text of the error message
anErrorHandlerAn identifier name for the function
aURLThe URL of the document containing the error
someCodeThe 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