Optional catch binding: catch without (e) (ES2019)
What you’ll learn
Section titled “What you’ll learn”- The
catch { }syntax and what it changes (and what it does not). - When ignoring the error is a deliberate, safe choice.
- How a bare
catchcan hide real bugs, and how to keep thetryblock narrow.
Summary
Section titled “Summary”TL;DR: since ECMAScript 2019, the parentheses and variable after catch are optional. try { ... } catch { ... } catches every exception exactly like catch (error), but does not create a binding you never use. It is pure syntax; runtime behavior is unchanged. Every current browser and server runtime supports it (details in Compatibility).
The problem it solves
Section titled “The problem it solves”Some failures only matter as a yes/no answer: did the JSON parse, does this engine support a feature, is storage available? Before ES2019 the grammar required a binding, so code declared variables like e, ignored or unused purely to satisfy the parser. Linters then flagged them as unused, and readers had to check whether the variable was really ignored.
Running the samples: save each sample as a .mjs file and run it with Node.js 22 (node sample.mjs). The outputs shown were produced with Node.js 22.23.
The OrdersPortal app keeps the user’s last order filters as a JSON string and falls back to defaults if the string is unreadable:
// OrdersPortal stores the last-used filters as JSON in a settings string.const DEFAULT_FILTERS = { status: 'open', pageSize: 25 };
// Before ES2019: a binding was required even when it was never used.function readFiltersBefore(saved) { try { return JSON.parse(saved); } catch (unused) { return DEFAULT_FILTERS; }}
// ES2019: omit the binding when the error itself does not matter.function readFilters(saved) { try { return JSON.parse(saved); } catch { return DEFAULT_FILTERS; }}
console.log(readFiltersBefore('{"status":"shipped","pageSize":50}'));console.log(readFilters('{"status":"shipped",'));Output:
{ status: 'shipped', pageSize: 50 }{ status: 'open', pageSize: 25 }How it works
Section titled “How it works”The specification’s Catch production has two forms: catch ( CatchParameter ) Block and catch Block. With the second form, the block runs in the same way when an exception is thrown, but no variable is created.
- The parentheses go with the binding.
catch () { }is aSyntaxError. finallyworks the same with either form.- Destructuring is still available when you do want a binding:
catch ({ message }). - It catches everything thrown in the
tryblock:SyntaxErrorfromJSON.parse, aTypeErrorfrom a typo, even non-Errorvalues such asthrow 'text'. There is no filtering by type in JavaScript.
// Feature detection: only "does this throw?" matters.function supportsRegExpFlag(flag) { try { new RegExp('', flag); return true; } catch { return false; }}console.log('v flag:', supportsRegExpFlag('v'), '| bogus flag:', supportsRegExpFlag('q'));
// finally still works without a binding.try { throw new Error('ignored');} catch { console.log('caught');} finally { console.log('finally ran');}
// The parentheses go away together with the binding: `catch ()` is a SyntaxError.try { new Function('try {} catch () {}');} catch (error) { console.log(error.name);}Output:
v flag: true | bogus flag: falsecaughtfinally ranSyntaxErrorThe last example keeps its binding on purpose, because it reads error.name.
Realistic example
Section titled “Realistic example”OrdersPortal remembers UI preferences in browser storage when it can. In browsers, reading window.localStorage or writing to it can throw (storage disabled by the user or by policy, quota exceeded), and preferences are optional, so most failures are ignored. The sample injects a storage getter so it runs in Node.js with stand-ins for localStorage:
// storage.mjs - remember OrdersPortal UI preferences when storage is available.// In browsers, accessing or writing localStorage can throw (storage disabled,// quota exceeded). Preferences are optional, so failures are ignored.export function createPreferences(getStorage, key = 'ordersPortal.prefs') { let storage = null; try { storage = getStorage(); } catch { // Storage blocked: fall back to in-memory preferences. } let memory = {};
return { load() { if (!storage) return memory; try { return JSON.parse(storage.getItem(key)) ?? {}; } catch { return {}; // corrupt or unreadable value: start fresh } }, save(prefs) { memory = prefs; if (!storage) return false; try { storage.setItem(key, JSON.stringify(prefs)); return true; } catch (error) { // Here the binding is kept: a full quota is expected, anything else is logged. if (error?.name !== 'QuotaExceededError') console.warn('Unexpected storage error:', error.message); return false; } }, };}
// --- Demo with stand-ins for window.localStorage.const map = new Map();const working = { getItem: (k) => map.get(k) ?? null, setItem: (k, v) => map.set(k, v) };const blocked = () => { throw new Error('The operation is insecure.'); };const full = { getItem: () => '{"theme":"dark"', setItem: () => { throw Object.assign(new Error('quota'), { name: 'QuotaExceededError' }); },};
const a = createPreferences(() => working);console.log(a.save({ theme: 'dark' }), a.load());const b = createPreferences(blocked);console.log(b.save({ theme: 'dark' }), b.load());const c = createPreferences(() => full);console.log(c.save({ theme: 'dark' }), c.load());Output:
true { theme: 'dark' }false { theme: 'dark' }false {}In the browser you would call createPreferences(() => window.localStorage). Note the mix: two catch blocks have no binding because every failure means the same thing, and the third keeps one because it treats an expected error differently from an unexpected one. That is the rule of thumb for the whole feature.
Common mistakes
Section titled “Common mistakes”-
Swallowing bugs along with the expected error. A bare
catchcatches typos and logic errors too:// A typo inside the try block is swallowed along with the expected error.function readPageSize(saved) {try {return JSON.parse(saved).pageSise.toFixed(0); // typo: pageSise} catch {return 25;}}console.log(readPageSize('{"pageSize": 50}')); // 25, and no hint why// Keep only the call that is expected to fail inside the try block.function readPageSizeSafe(saved) {let parsed;try {parsed = JSON.parse(saved);} catch {return 25; // only JSON.parse is inside the try block}return Number(parsed.pageSize ?? 25);}console.log(readPageSizeSafe('{"pageSize": 50}'), readPageSizeSafe('not json'));Output:
25, then50 25. The first version hides aTypeErrorand always returns the default; the second keeps thetryblock to the one call that is expected to fail. -
Dropping the binding where you should log. If a failure would be useful to diagnose later, keep
catch (error)and record it. Optional binding is for errors that are genuinely irrelevant. -
Writing
catch (). Empty parentheses are a syntax error; remove both. -
Empty blocks with no comment.
catch {}with nothing inside looks like a mistake. Add a short comment that says why ignoring is safe.
When to use it and when not to
Section titled “When to use it and when not to”Use catch { } when the only information you need is that something threw:
- Parsing optional input with a fallback (
JSON.parse,new URL()). - Feature detection (
new RegExp('', 'v'), constructing an API that may not exist). - Best-effort side effects whose failure is acceptable (optional caching, analytics).
Keep the binding when you need to tell error types apart, re-throw unexpected errors, wrap the error with cause, or log it.
Compatibility
Section titled “Compatibility”According to MDN’s browser compatibility data, optional catch binding is supported in Chrome 66, Edge 79, Firefox 58, Safari 11.1 (iOS Safari 11.3), Node.js 10.0.0, Deno 1.0 and Bun 1.0. Internet Explorer never supported it. Because it is syntax, it cannot be polyfilled; a transpiler such as Babel or TypeScript (with a target below ES2019) rewrites it by adding an unused variable.
Interview questions
Section titled “Interview questions”1. What does optional catch binding change at runtime?
Nothing about which exceptions are caught or how control flows. It only removes the requirement to declare a variable for the thrown value. catch { } catches everything catch (e) { } catches.
2. When should you keep the binding?
Whenever the error affects what you do: distinguishing expected from unexpected errors, re-throwing, logging, or wrapping it as the cause of a new error.
3. Senior scenario: a code review finds dozens of catch {} blocks with default return values across OrdersPortal. How do you decide which are acceptable?
For each one, check what is inside the try block. If it contains only a call whose failure is expected and fully handled by the fallback (a parse, a feature check), it is fine; ask for a comment explaining why. If the try block wraps larger logic, narrow it to the expected call so bugs surface. If the failure would matter in production (payments, persistence), require a binding and logging or a re-throw. Add a lint rule such as ESLint’s no-empty (which flags empty blocks, including empty catch blocks) so silent catches need an explicit comment.
Key takeaways
Section titled “Key takeaways”- ES2019 makes the
catchbinding optional:try { } catch { }. - It changes syntax only; every exception is still caught.
- Use it when only “did it throw?” matters, and keep the
tryblock narrow so bugs are not swallowed. - Keep
catch (error)whenever you log, re-throw, wrap or branch on the error.
Related pages
Section titled “Related pages”- Error handling:
try,catch,finallyandthrowin depth. - Error cause: when you do need the error, wrap it without losing it.
- Promise.finally: outcome-independent clean-up for promises.
- JSON: parsing and its failure modes.
Official references
Section titled “Official references”- ECMAScript Language Specification, The
tryStatement (current draft; the optional binding was first published in ECMAScript 2019, 10th edition) - ECMAScript 2019 Language Specification (ECMA-262, 10th edition)
- TC39 proposal: Optional catch binding
- MDN: try…catch