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;
}
})();
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;
}
})();
If you want to allow optional catch
binding, you can turn this rule off.