In the browser, define the window.onerror function. In a node attached to an uncaughtException event using process.on() .
This should be ONLY if you need to catch all the errors, for example, in the spec slider or console.log / debugging implementation. Otherwise, you will find yourself in a world of pain, trying to track strange behavior. Like some of them, in normal daily code, the try / catch is the right and best way to handle errors / exceptions.
For reference in the first case, see this (about window.error in browsers) and this (about uncaughtException in node) . Examples:
Browser
window.onerror = function(error) { // do something clever here alert(error); // do NOT do this for real! };
Node.js
process.on('uncaughtException', function(error) { // do something clever here alert(error); // do NOT do this for real! });
Sukima
source share