Skip to content
This repository has been archived by the owner on Jul 16, 2019. It is now read-only.

cjihrig/no-optional-catch-binding

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

ESLint rule to flag catch clauses with no error variable binding

Resources

License

Stars

Watchers

Forks

Packages

No packages published