Can I use catch (e if e instanceof SyntaxError) in Node.js javascript?

I read about try catch (e if e instanceof ...) blocks on MDN , however, having tried it in Node. js, I get SyntaxError: Unexpected token if.

If this does not work, is there any other way to catch certain exceptions, and not everything that can happen?

+6
source share
1 answer

To cite the MDN document you are attached to:

Note. This functionality is not part of the ECMAScript specification.

and

JavaScript 1.5, NES 6.0: Added multiple catch clauses (Netscape extension).

like this: No, this is not possible in Node.js. However, 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 }] 
+11
source

Source: https://habr.com/ru/post/915108/


All Articles