I\'m using TypeScript for a reasonably large project, and am wondering what the standard is for the use of Error
s. For example, say I hand an index out of bounds ex
Don't forget about switch statements:
default
.instanceof
can match on superclass.constructor
will match on the exact class.function handleError() {
try {
throw new RangeError();
}
catch (e) {
switch (e.constructor) {
case Error: return console.log('generic');
case RangeError: return console.log('range');
default: return console.log('unknown');
}
}
}
handleError();