no-try
Disallow try/catch/finally.
Targeted pattern scopeâ
This rule targets TryStatement nodes.
What this rule reportsâ
- Any
try { ... } catch { ... }ortry/finallypattern
Why this rule existsâ
This encourages explicit, value-oriented control flow over exception-based branching.
â Incorrectâ
try {
run();
} catch {
recover();
}
â Correctâ
const result = runSafely();
if (!result.ok) {
return recover(result.error);
}
Additional examplesâ
// â try/catch around JSON parsing
let payload;
try {
payload = JSON.parse(raw);
} catch {
return { ok: false, error: "Invalid JSON" };
}
// â
Dedicated safe parser that returns a result
const parseJson = (text: string) => {
const parsed = safeJsonParse(text);
return parsed.success
? { ok: true, value: parsed.value }
: { ok: false, error: "Invalid JSON" };
};
return parseJson(raw);
ESLint flat config exampleâ
import immutable from "eslint-plugin-immutable-2";
export default [
{
files: ["**/*.{js,mjs,cjs,ts,mts,cts,tsx}"],
plugins: { immutable },
rules: {
"immutable/no-try": "error",
},
},
];
When not to use itâ
try/finally remains valuable for resource cleanup (file handles, locks, tracing spans). If your runtime boundary needs exception handling for interoperability, keep the rule off in those adapters while preserving it in pure domain code.
Rule catalog ID: R912