How to handle uncaught Exceptions in javascript without a try/catch-block?

Posted by user344238 on Stack Overflow See other posts from Stack Overflow or by user344238
Published on 2010-05-18T16:33:09Z Indexed on 2010/05/18 18:50 UTC
Read the original article Hit count: 145

Filed under:
|

What i try to accomplish is to register a global handler to catch all uncaught exceptions. Searching the web i only managed to find people pointing out window.onerror but this doesn't do the trick for me. Apparently window.onerror only gets called upon errors and not upon exceptions. Assume the following code:

    function windowError(message, url, line) {
        alert(message, url, line);
    }
    window.onerror=windowError;
    throw("uncaught");

The obviously uncaught exception won't trigger the windowError handler. (Using Firefox 3.6.3)

Any suggestions?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about exceptions