📝 Disallow try-catch[-finally] and try-finally patterns.
💼🚫 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.
Try statements are not part of functional programming. See no-throw-statements for more information.
/* eslint functional/no-try-statements: "error" */
try {
doSomethingThatMightGoWrong(); // <-- Might throw an exception.
} catch (error) {
// Handle error.
}/* eslint functional/no-try-statements: "error" */
doSomethingThatMightGoWrong() // <-- Returns a Promise
.catch((error) => {
// Handle error.
});This rule accepts an options object of the following type:
type Options = {
allowCatch: boolean;
allowFinally: boolean;
};const defaults = {
allowCatch: false,
allowFinally: false,
};If true, try-catch statements are allowed.
If true, try-finally statements are allowed.