Can I use a try/catch in JavaScript without specifying the catch argument/identifier?

Optional catch binding in 2019

Node.js

In Node.js, this feature is called Optional Catch Binding and is supported since Node.js version 10.3, see https://node.green.

Typescript

In Typescript, this is allowed since version 2.5.

Browser support

  • Chrome: since 68
  • Firefox: since 58
  • Edge, IE, Safari: no support for now

Standard

The proposal is currently Stage 4, meaning that its implementation is finished and it is guaranteed to be included into the next version of the ECMAScript standard.

So this is a perfectly legitimate syntax now according to the standard if you are using Node.js or transpiling your browser code using Babel:

try {

} catch {
  // No need for the `(error)` after `catch`!
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)