The try - catch sample that you specify in your question is the right way - you want to try - catch block, not a way to silently load through module errors (in general, always be extremely careful when handling exceptions all over the world and continue in this way these are data corruption errors that you will only find after 6 months).
Your real problem is this:
... in fact, these functions often add several other event handlers, which in turn will require try / catch. I get very repeating code filled with try / catch blocks.
The fix for this is Promise . This is a new structure built into most browsers, but easily mixed into slow browsers (ah, IE), which gives you a standard way to control both an event callback and an exception from an event.
With Promise your code promises to always do something: allow / delete or reject / fail.
function moduleA() { return new Promise(function (resolve, reject) { try{ var result = window.thisDoesntExist(); resolve(resolve);
This is better because instead of try - catch blocks instead of catch sockets in each callback, you can instead chain promises:
moduleA(). then(moduleB). then(moduleC). catch(errorHandler); // Catch any error from A, B, or C
You can also handle the error and continue:
moduleA(). catch(continuableErrorHandler). // Catch any error from A then(moduleB). then(moduleC). catch(errorHandler); // Catch any error from B or C
You still need a lot of try - catch blocks in callbacks, but everything wrapped in Promise can be handled in the same modular way.
Next in JS are async and await , but you can use them now with the transpiler. They use promises to make code that is much easier to read, and most importantly, there is one try for you - a catch at the top that collects exceptions from the Promise chain.
This answer is already too long, but I wrote about it in more detail .
TL DR: If your problem is βvery repeating [callback] code filled with try / catch blocksβ, try using Promise instead.