I used to put a try...catch inside any method of my JS classes:
var MyConstructor = function() {
this.init = function() {
try {
// the method code...
} catch(error) {
// the error manager log actions
}
};
// other methods, with the same try/catch usage
};
This way, keeping a code interface relatively simple, I thought any error inside my code would have been caught and logged/managed.
var myInstance = new MyConstructor();
Instead, is it enough one global catch block per script? Caring to throw each possible (or noteworthy) error, it seems to me enough to know every error occurring in the app:
// no try...catch inside the classes, but only a global try...catch per script:
try {
var myInstance = new MyConstructor();
} catch(error) {
/*
log in the needed environment
(e.g. client-side, via console, or to the server...)
*/
}
I searched and read threads on Stackoverflow and remarkable resources on line about JavaScript error management.
In this phase I am interested in finding the best way to find all the errors more than managing them for a graceful behaviour of the user interface.
Isn't it the right approach? I am open to any suggestion.