Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q234 How can I trap errors?

irt.org | Knowledge Base | JavaScript | Misc | Q234 [ previous next ]

Q234 How can I trap errors?

In Netscape Navigator 3 and above its possible to trap errors with:

<SCRIPT LANGUAGE="JavaScript"><!--
function deal_with_error(msg, url, line) {
    alert('Message: ' + msg + '\n' + 'In file: ' + url + '\n' + 'At line: ' + line);
    return true;
}

self.onerror = deal_with_error;

// The next line causes a error:

alert(x);

//--></SCRIPT>

This does trap errors on Netscape Navigator 3 and above which supports the onerror event handler - although it is always best to try and anticipate the error *before* it happens and take appropriate action:

<SCRIPT LANGUAGE="JavaScript"><!--
if (window.x)
    alert(x);
else
    alert('x is not defined');
//--></SCRIPT>

Feedback on 'Q234 How can I trap errors?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.