Search code examples
javascriptjquerytry-catchthrow

attaching an event for errors js/jquery


I'm looking for a hook to use whenever an error is fired. I'm aware that you can try/catch but I want something like jQuery's .error but bound to all errors.

Anyone know of anything like this?


Solution

  • Perhaps this is what you are looking for window.onerror

    Summary

    An event handler for runtime script errors.

    Note that some/many error events do not trigger window.onerror, you have to listen for them specifically.