# Universal and conditional catch blocks with the new when keyword

**URL:** <https://es.discourse.group/t/universal-and-conditional-catch-blocks-with-the-new-when-keyword/2122>\
**Category:** 🦋 Proposals\
**Tags:** proposal\
**Created:** [August 28, 2024, 4:14am UTC](https://es.discourse.group/t/universal-and-conditional-catch-blocks-with-the-new-when-keyword/2122 "2024-08-28T04:14:49Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [August 28, 2024, 8:28am UTC](https://es.discourse.group/t/universal-and-conditional-catch-blocks-with-the-new-when-keyword/2122/2 "2024-08-28T08:28:28Z")

</div>

Related threads:

> [@Catch instanceof guards](https://es.discourse.group/t/catch-instanceof-guards/1160):
>
> It would be really nice to be able to write try { // some code } catch (error instanceof MyCustomError) { // handle the error } catch (error instanceof AnotherCustomError) { // handle the other error } instead of the more verbose try { // some code } catch (error) { if (error instanceof MyCustomError) { // handle the error } else if (error instanceof AnotherCustomError) { // handle the other error } else { throw error; } }

> [@\[Need Champion\] Catch guards](https://es.discourse.group/t/need-champion-catch-guards/1698):
>
> Proposal: [GitHub - 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: 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.

---

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