How to handle uncached exceptions in javascript without try / catch-block?

What I'm trying to do is register a global handler to catch all the uncaught exceptions. Searching the Internet I managed to find people pointing out window.onerror , but that doesn't do the trick for me. Obviously, window.onerror raises only errors, not exceptions. Assume the following code:

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

Obviously, an uncaught exception does not raise a windowError handler. (Using Firefox 3.6.3)

Any suggestions?

+7
javascript exception
source share
2 answers

Errors are caught in the same way as exceptions in javascript, and in fact in your example the message receives a warning (Firefox 3.6.3).

+4
source share

As far as I know, you will need try / catch blocks for this to happen. This is what you need to know when to handle what kinds of errors.

+2
source share

All Articles