no-optional-catch-binding
catch
blocks (no-optional-catch-binding)
disallow optional error variable binding in JavaScript allows error variables to be optionally omitted from catch
clauses. For example:
(() => {
try {
throw new Error();
return 1;
} catch {
// The caught exception is not used, and has been omitted.
return 2;
}
})();
Rule Details
This rule requires that each catch
clause includes an error variable binding.
An example of incorrect code for this rule:
/*eslint no-optional-catch-binding: "error"*/
(() => {
try {
throw new Error();
return 1;
} catch {
return 2;
}
})();
An example of correct code for this rule:
/*eslint no-optional-catch-binding: "error"*/
(() => {
try {
throw new Error();
return 1;
} catch (err) {
return 2;
}
})();
When Not To Use It
If you want to allow optional catch
binding, you can turn this rule off.