Skip to content

Latest commit

 

History

History
64 lines (43 loc) · 1.24 KB

no-try-statements.md

File metadata and controls

64 lines (43 loc) · 1.24 KB

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

💼🚫 This rule is enabled in the following configs: no-exceptions, 🔒 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.