single try and multiple error handling in javascript
Table of contents
No headings in the article.
Unlike java in javascript we have only single block to handle error
try {
// un-comment line below to see (reference error)
// show();
// un-comment line below to see (type error)
// a = "".toFixed()
} catch (e) {
if (e instanceof TypeError) {
// handle type error
console.log("You have type error");
}
else if (e instanceof ReferenceError) {
// handle reference error
console.log("You have reference error");
}
else{
console.log("other error")
}
}