How would you implement different types of errors, so you\'d be able to catch specific ones and let others bubble up..?
One way to achieve this is to modify the
Using try-catch-finally.js, you can call the _try
function with an anonymous callback, which it will call, and you can chain .catch
calls to catch specific errors, and a .finally
call to execute either way.
_try(function () {
throw 'My error';
})
.catch(Error, function (e) {
console.log('Caught Error: ' + e);
})
.catch(String, function (e) {
console.log('Caught String: ' + e);
})
.catch(function (e) {
console.log('Caught other: ' + e);
})
.finally(function () {
console.log('Error was caught explicitly');
});
_try(() => {
throw 'My error';
}).catch(Error, e => {
console.log(`Caught Error: ${e}`);
}).catch(String, e => {
console.log(`Caught String: ${e}`);
}).catch(e => {
console.log(`Caught other: ${e}`);
}).finally(() => {
console.log('Error was caught explicitly');
});