Skip to content

Latest commit

 

History

History
58 lines (40 loc) · 1.01 KB

no-try-statement.md

File metadata and controls

58 lines (40 loc) · 1.01 KB

Disallow try-catch[-finally] and try-finally patterns (no-try-statement)

This rule disallows the try keyword.

Rule Details

Try statements are not part of functional programming. See no-throw-statement for more information.

Examples of incorrect code for this rule:

/* eslint functional/no-try-statement: "error" */

try {
  doSomethingThatMightGoWrong(); // <-- Might throw an exception.
} catch (error) {
  // Handle error.
}

Examples of correct code for this rule:

/* eslint functional/no-try-statement: "error" */

doSomethingThatMightGoWrong() // <-- Returns a Promise.
  .catch((error) => {
    // Handle error.
  });

Options

This rule accepts an options object of the following type:

{
  allowCatch: boolean;
  allowFinally: boolean;
}

The default options:

{
  allowCatch: false,
  allowFinally: false
}

allowCatch

If true, try-catch statements are allowed.

allowFinally

If true, try-finally statements are allowed.