Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q234 How can I trap errors?

You are here: irt.org | FAQ | JavaScript | Misc | Q234 [ previous next ]

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?'

©2018 Martin Webb