1.0.0 • Published 6 years ago

no-optional-catch-binding v1.0.0

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

no-optional-catch-binding

Current Version Build Status via Travis CI Dependencies

disallow optional error variable binding in catch blocks (no-optional-catch-binding)

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.