I read about try catch(e if e instanceof ...) blocks on MDN, however, upon trying it in Node.js, I get a SyntaxError: Unexpected token if.
If this doesn't work, is there another way to catch specific exceptions, instead of everything that might occur?
To cite the MDN doc you linked to:
Note: This functionality is not part of the ECMAScript specification.
and
JavaScript 1.5, NES 6.0: Added multiple catch clauses (Netscape extension).
so: No, this won't be possible in Node.js. Yet, of course you can use the following syntax as a workaround:
try {
try_statements
} catch (e) {
if (e instanceof ...)
catch_statements_1
else if (e instanceof ...)
catch_statements_2
else
throw e;
} [finally {
finally_statements
}]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With