# Is it possible to catch error from a promise without using await?

**URL:** <https://es.discourse.group/t/is-it-possible-to-catch-error-from-a-promise-without-using-await/973>\
**Category:** I have questions\
**Created:** [September 6, 2021, 2:13pm UTC](https://es.discourse.group/t/is-it-possible-to-catch-error-from-a-promise-without-using-await/973 "2021-09-06T14:13:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aleen42](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aleen42/32/461_2.png) [@aleen42](https://es.discourse.group/u/aleen42)\
**Post date:** [September 6, 2021, 2:13pm UTC](https://es.discourse.group/t/is-it-possible-to-catch-error-from-a-promise-without-using-await/973/1 "2021-09-06T14:13:23Z")

</div>

As we known that, there is a difference between the following cases:

```javascript
try { awat Promise.reject(1) } catch { console.log('caught') } // => "caught"
try { Promise.reject(1) } catch { console.log('caught') } // => throw "Uncaught (in promise) 1"

```

Is it possible to eliminate the difference?

---

<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:** [September 6, 2021, 4:28pm UTC](https://es.discourse.group/t/is-it-possible-to-catch-error-from-a-promise-without-using-await/973/2 "2021-09-06T16:28:08Z")

</div>

Not in the language.

Both node and browsers provide an event listener for you to catch an unhandled rejection, but you can't handle that "synchronously" without `await`.

---

<div class="post-metadata">

**Author:** ![aleen42](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aleen42/32/461_2.png) [@aleen42](https://es.discourse.group/u/aleen42)\
**Post date:** [September 7, 2021, 1:41am UTC](https://es.discourse.group/t/is-it-possible-to-catch-error-from-a-promise-without-using-await/973/3 "2021-09-07T01:41:36Z")

</div>

@ljharb That may confuse someone that if an `async` function does not return a `await` promise, and we can't use `try...catch` statements to catch such a situation:

```javascript
try { (async function f() { return await Promise.reject(1) })() } catch { console.log('caught') } // => "caught"
try { (async function f() { return Promise.reject(1) })() } catch { console.log('caught') } // => throw "Uncaught (in promise) 1"

```

In this case, we should use `Promise.prototype.catch` to catch any unhandled rejection, but I just want to know there is any other idea to eliminate the confusion.

---

<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:** [September 7, 2021, 1:52am UTC](https://es.discourse.group/t/is-it-possible-to-catch-error-from-a-promise-without-using-await/973/4 "2021-09-07T01:52:36Z")

</div>

No, it's the responsibility of the creator of the Promise to ensure its errors are handled.

It's also _perfectly fine_ for the author NOT to handle them - `Promise.reject();` is a valid program.

---

<div class="post-metadata">

**Author:** ![aleen42](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aleen42/32/461_2.png) [@aleen42](https://es.discourse.group/u/aleen42)\
**Post date:** [September 7, 2021, 1:54am UTC](https://es.discourse.group/t/is-it-possible-to-catch-error-from-a-promise-without-using-await/973/5 "2021-09-07T01:54:36Z")

</div>

👌
