Skip to content

Latest commit

 

History

History
69 lines (47 loc) · 1.37 KB

no-try-statements.md

File metadata and controls

69 lines (47 loc) · 1.37 KB

Disallow try-catch[-finally] and try-finally patterns (functional/no-try-statements)

💼🚫 This rule is enabled in the following configs: noExceptions, 🔒 strict. This rule is disabled in the following configs: ☑️ lite, ✅ recommended.

This rule disallows the try keyword.

Rule Details

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

❌ Incorrect

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

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

✅ Correct

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

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

Options

This rule accepts an options object of the following type:

type Options = {
  allowCatch: boolean;
  allowFinally: boolean;
};

Default Options

const defaults = {
  allowCatch: false,
  allowFinally: false,
};

allowCatch

If true, try-catch statements are allowed.

allowFinally

If true, try-finally statements are allowed.