With this code:
try {
} catch {
}
ESLint gives this error:
Parsing error: Unexpected token {
Is there an ESLint rule to enable optional catch binding?
It's an ES2019 feature, so make sure you set an ecmaVersion
of 10. For example, your .eslintrc.json
should have:
{
"parserOptions": {
"ecmaVersion": 10
}
}
Setting parser options helps ESLint determine what is a parsing error.
Similarly, for the online demo, make sure to select 2019
from the "ECMA Version" dropdown list.
For some reason
{
"parserOptions": {
"ecmaVersion": 10
}
}
did not work for me.
But this did:
"rules": {
"no-empty": ["error", { "allowEmptyCatch": true }]
},
For more info see https://eslint.org/docs/rules/no-empty#allowemptycatch
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