ayushg3112 at gmail.com (2018-04-24T09:42:31.116Z)
I propose that in `Promises`, we accept another function which returns a
`boolean` as an argument to `catch`. It will enable us to write code like
this:
```js
return somePromise
.catch((reason) => reason instanceof ValidationError, reason => handleValidationError(reason)) // handle ValidationErrors
.catch((reason) => reason instanceof InternalError, reason => handleInternalError(reason)) // handle InternalErrors
.catch(reason => handleOtherErrors(reason)) // catch all others
```
If the passed function evaluates to `true`, call the actual rejection
handler. If none of the catch are eligible to handle the rejection, it
causes an unhandled rejection.
I propose that in `Promises`, we accept another function which returns a `boolean` as an argument to `catch`. It will enable us to write code like this: ```js return somePromise .catch((reason) => reason instanceof ValidationError, reason => handleValidationError(reason)) // handle ValidationErrors .catch((reason) => reason instanceof InternalError, reason => handleInternalError(reason)) // handle InternalErrors .catch(reason => handleOtherErrors(reason)) // catch all others ``` If the passed function evaluates to `true`, call the actual rejection handler. If none of the catch are eligible to handle the rejection, it causes an unhandled rejection. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180424/512fc72d/attachment-0001.html>