views:

44

answers:

2

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?

+2  A: 

As far as i know you'll need try/catch blocks to make this happen. That's sort of the point, that you need to know when to handle which kinds of errors.

JHollanti
A: 

Errors are caught the same way as exceptions in javascript and in fact, in your example the message get's alerted (Firefox 3.6.3).

Pablo Cabrera
That is quite odd. It don't get any alert with Firefox 3.6.3.
Taloncor
I've tried your example on a simple html page and it does work. That's odd that on your Firefox is not 'alerting'... Have you tried on another browser?
Pablo Cabrera