Catch Guard S0
- Stage: Stage 0
- Status: Active
- ECMAScript edition: —
- Synchronized: Aug 28, 2026
- 中文译文 · Source repository
The Catch Guard proposal addresses the lack of ergonomic error type handling in JavaScript by adding catch guards, allowing developers to catch exceptions only when they match specific classes. It proposes two syntax options: a new catch statement with a BindingGuard type, or a new CatchPatten statement combined with pattern matching.
The README below comes from the upstream repository and may contain outdated stage or status metadata. Use the proposal details above as the current source of truth.
ECMAScript Catch Guards
This proposal adds the catch guards to the language, enabling developers to catch exceptions only when they match a specific class or set of classes.
This proposal draws heavily from similar features available in Java, C#, Ruby, and Python.
Problem statement
Javascript doesn't provide an ergonomic way of treating different types of errors.
Status
Champion: Willian Martins (Netflix, @wmsbill),
Stage: 0
Lastest update: draft created
Motivation
-
Developer ergonomics:
Today, developers have to catch all Errors, add an
iforswitchstatement and rethrow even when they want to catch one particular type of error: -
Parity with other languages:
Scoping error handling to specific types is a common construct in several programming languges, as: Java, C#, Ruby, and Python.
-
Code/Engine Optimization:
Engines can skip the block entirely if the error doesn't match the correct type.
Syntax options
The current implementation uses the following syntax:
Where CatchParameter is:
BindingIdentifier[?Yield, ?Await]BindingPattern
Option 1 (New Catch Statement):
This proposal introduces a new Binding type for the CatchParameter called BindingGuard; this new bind type's shape and semantics are subject to stage 1 development.
Option 2 (New CatchPatten statement):
This option can be used in conjunction with option one or leveraged on the Pattern Matching proposal to bind different error patterns (syntax and semantics are subject to stage 1 development), making the catch statement keep its current syntax.
Implementations
- Babel Plugin //TBD