# \[Need Champion\] Catch guards

**URL:** <https://es.discourse.group/t/need-champion-catch-guards/1698>\
**Category:** 🦋 Proposals\
**Created:** [April 22, 2023, 7:45pm UTC](https://es.discourse.group/t/need-champion-catch-guards/1698 "2023-04-22T19:45:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeengbe](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jeengbe/32/1722_2.png) [@jeengbe](https://es.discourse.group/u/jeengbe)\
**Post date:** [April 22, 2023, 7:45pm UTC](https://es.discourse.group/t/need-champion-catch-guards/1698/1 "2023-04-22T19:45:45Z")

</div>

#### Proposal: [https://github.com/jeengbe/proposal-catch-guards](https://github.com/jeengbe/proposal-catch-guards)

The document proposes a new syntax for catch clauses with guards for better code readability:

```js
try {
  someFunction();
} catch ErrorA (err) {
  // Do something
} catch ErrorB | ErrorC (err) {
  // Do another thing
} catch {
  // Do a third thing
} finally {
  // Clean up
}

```

The proposal is in need of a champion and a polished changeset to the spec.

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [April 22, 2023, 8:15pm UTC](https://es.discourse.group/t/need-champion-catch-guards/1698/2 "2023-04-22T20:15:42Z")

</div>

This is commonly called catch guards, and there’s an existing proposal that’s planning to follow up pattern matching.

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/senocular/32/642_2.png) [@senocular](https://es.discourse.group/u/senocular)\
**Post date:** [April 22, 2023, 8:24pm UTC](https://es.discourse.group/t/need-champion-catch-guards/1698/3 "2023-04-22T20:24:58Z")

</div>

Proposal mentioned above: [GitHub - wmsbill/proposal-catch-guards: TC39 proposal for catch guards](https://github.com/wmsbill/proposal-catch-guards)

---

<div class="post-metadata">

**Author:** ![jeengbe](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jeengbe/32/1722_2.png) [@jeengbe](https://es.discourse.group/u/jeengbe)\
**Post date:** [April 22, 2023, 9:12pm UTC](https://es.discourse.group/t/need-champion-catch-guards/1698/4 "2023-04-22T21:12:44Z")

</div>

Hi @ljharb, @senocular,

thanks for your comments. I have updated the proposal accordingly and added a section that compares the document with other proposals.

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [April 23, 2023, 11:48pm UTC](https://es.discourse.group/t/need-champion-catch-guards/1698/5 "2023-04-23T23:48:18Z")

</div>

I wouldn’t support anything that has instanceof semantics, because instanceof is not reliable or robust.

---

<div class="post-metadata">

**Author:** ![rafageist](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/rafageist/32/2200_2.png) [@rafageist](https://es.discourse.group/u/rafageist)\
**Post date:** [September 6, 2024, 1:51pm UTC](https://es.discourse.group/t/need-champion-catch-guards/1698/6 "2024-09-06T13:51:59Z")

</div>

That would be more in line with typescript, but not javascript because | is the binary OR operator. Instead you can see a proposal closer to the ECMA specifications

[Universal and conditional catch blocks with the new when keyword](https://es.discourse.group/t/universal-and-conditional-catch-blocks-with-the-new-when-keyword/2122)
