Skip to content

TypeScript · correctness

no-fat-try-blocks

eslint:no-fat-try-blocks

Disallow `try` blocks containing more than three top-level operations that can throw.

Default
error
Fix
none
Languages
typescript

Why

A broad `try` block obscures which operation failed and encourages one catch clause to recover from unrelated errors.

Fix

Keep only the operations that share one recovery policy inside the `try` block and move other work outside it.

Before / after

Executed by this rule’s unit tests.

Before

A try block contains four throwing operations

src/load.ts · focus
function f() { try { const a = one(); const b = two(); const c = three(); const d = four(); } catch (error) { handle(error); } finish(); }

After

A try block contains three throwing operations

src/load.ts · focus
function f() { try { const a = one(); const b = two(); const c = three(); } catch (error) { handle(error); } finish(); }

Limits

  • The rule uses syntax to identify throwing operations and exempts generated files, finally blocks, rethrows, and terminal error boundaries.

Message IDs

fatTryBlock