Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> JavaScript >> Snippet

20 Error handling


JavaScript fires an onerror event if an error occurs.

The user must add onError code into any tags where an error must be caught.

You can tell JavaScript to run a custom error handling function like this :

window.onerror = myErrorHandler;

where the windows onerror  proprery is assigned the name of your customized error handling function .
The function must accept 3 parameters - a string message, URL of page causing error, and line number of error.

function myErrorHandler ( msg, url, line) {  
  //your code goes here
  return true ;
  }