views:

410

answers:

1

I'm looking to log unhandled javascript exceptions. Is there an event that fires when an exception isn't caught? I'm looking to catch the exceptions before they cause javascript errors in the browser, but I'd rather not run my entire application inside of a try/catch. Any help would be appreciated. Thanks!

Update: tvanfosson pointed out onerror as a possibility. It is not part of a spec and is only available in IE or Gecko based browsers.

For more information - http://books.google.com/books?id=tKszhx-XkzYC&pg=PA386&lpg=PA386&dq=safari+onerror+javascript&source=web&ots=gQaGbpUnjG&sig=iBCtOQs0aH_EAzSbWlGa9v5flyo#PPA387,M1

OnError Support Table - http://www.quirksmode.org/dom/events/error.html

Mozilla's documentation - https://developer.mozilla.org/En/DOM/Window.onerror

WebKit Bug Report - https://bugs.webkit.org/show_bug.cgi?id=8519

+3  A: 

Try using an onerror handler. Docs from w3schools. This will allow you to do something when an error is detected, but probably won't let you continue in a graceful way that a try/catch block would. It also seems to be browser dependent as I couldn't get the example referenced on their site to work in Safari, but I could in Firefox.

tvanfosson
Thanks - that seems to work alright
Nathaniel Reinhart