Skip to content

Instantly share code, notes, and snippets.

@ethagnawl
Forked from anonymous/gist:4302682
Last active December 9, 2015 17:18
Show Gist options
  • Save ethagnawl/4302686 to your computer and use it in GitHub Desktop.
Save ethagnawl/4302686 to your computer and use it in GitHub Desktop.
An onerror handler that's a helluva lot more useful than `... catch(e) { alert(e) }`.You can easily hook this into a custom Google Analytics event to log your app's errors. Inspired by: http://bytes.com/topic/javascript/answers/90742-try-catch-error-handling-display-line-number
onerror = (err, file, line) ->
logger """ # console.log, alert, whatever
The following error occured: #{err}
In file: #{file}
At line: #{line}
"""
var onerror = function(err, file, line) {
return alert("The following error occured: " + err + "\nIn file: " + file + "\nAt line: " + line);
};
@ethagnawl
Copy link
Author

Whoops - I didn't mean to publish this anonymously.

Forking for posterity. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment