---
title: "Uncaught (in promise): how do I catch rejected promises properly?"
description: "Uncaught (in promise) means a promise rejected and nothing handled it. Learn where to put catch, how try and await work together, and how to log unhandled rejections."
url: https://www.danny.engineering/answer/javascript/uncaught-in-promise-how-do-i-catch-rejected-promises-properly
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T17:24:00.000Z
tags: ["Javascript"]
---

# Uncaught (in promise): how do I catch rejected promises properly?

## The short answer


A promise rejected and no code attached a handler for it. Add a `.catch()` to the end of the chain, or wrap the `await` in `try...catch`. Make sure every promise you start is either awaited, returned, or given a handler.


```javascript
try {
  const response = await fetch('/api/data');
  if (!response.ok) throw new Error(`HTTP ${response.status}`);
  const data = await response.json();
  render(data);
} catch (error) {
  showError(error);
}
```


## Why it happens


When a promise rejects, the error travels down the chain until it meets a rejection handler. If it reaches the end of the chain with no handler, the browser logs "Uncaught (in promise)" and Node.js emits an `unhandledRejection` event. In current Node.js releases the default is to crash the process for unhandled rejections.


A normal `try...catch` only catches errors thrown while the `try` block runs. A promise that rejects later is not caught unless you `await` it inside the block. Common causes are:

- Calling an async function without `await` or `.catch()`, often called a floating promise.
- Wrapping a `.then()` chain in `try...catch` without awaiting it.
- A `.catch()` handler that throws again, or a `.then()` placed after the `.catch()` that throws.
- Starting several promises and awaiting only the first, so a later one rejects with nothing listening.

## How to fix it


### Await inside try...catch


This is the most readable option for async functions. The `await` is what lets `catch` see the rejection.


```javascript
async function save(item) {
  try {
    await api.save(item);
  } catch (error) {
    console.error('Save failed', error);
    throw error; // rethrow if the caller should know
  }
}
```


### End promise chains with .catch()


When you use `.then()`, put a single `.catch()` at the end so it handles a rejection from any step.


```javascript
loadUser(id)
  .then((user) => loadPosts(user.id))
  .then(renderPosts)
  .catch(showError);
```


### Handle fire-and-forget calls


If you deliberately do not await something, such as analytics in an event handler, still attach a handler.


```javascript
button.addEventListener('click', () => {
  trackClick().catch((error) => console.warn('Tracking failed', error));
  openMenu();
});
```


### Handle every promise you start in parallel


If you start several requests, await them together so any rejection is caught. Use `Promise.allSettled` when you want every result even if some fail.


```javascript
const [user, settings] = await Promise.all([loadUser(), loadSettings()]);
```


### Add a global safety net for logging


Global handlers are for reporting, not for normal error handling. They tell you what you missed.


```javascript
// Browser
window.addEventListener('unhandledrejection', (event) => {
  reportError(event.reason);
});

// Node.js
process.on('unhandledRejection', (reason) => {
  console.error('Unhandled rejection', reason);
  process.exitCode = 1;
});
```


## Common pitfalls

- Assuming `fetch` rejects on 404 or 500. It only rejects on network failure; check `response.ok` yourself.
- Rejecting with a string instead of an `Error`. You lose the stack trace that tells you where it came from.
- Catching and doing nothing. An empty `catch` hides real bugs; at least log the error.
- Returning inside `try` without `await`, as in `return fetchData()`. The rejection skips your `catch`; use `return await fetchData()` when you want it caught there.
- Using a global handler instead of local ones. By then you have lost the context to recover.

## Related reading

- [MDN: Using promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)
- [MDN: unhandledrejection event](https://developer.mozilla.org/en-US/docs/Web/API/Window/unhandledrejection_event)
- [Node.js: unhandledRejection event](https://nodejs.org/api/process.html#event-unhandledrejection)
