# try/catch in Async Code — Node.js

Source: https://www.geekswithgeeks.com/en/nodejs/node-try-catch-async

> Catching errors from await, and from Promise chains.

## Wrapping await

A rejected Promise inside an `async` function is thrown at the `await` — catch it with `try/catch`.

```javascript
import { readFile } from "node:fs/promises";

async function loadConfig() {
  try {
    const raw = await readFile("config.json", "utf8");
    return JSON.parse(raw);
  } catch (err) {
    console.error("Could not load config:", err.message);
    return {};
  }
}
```

## try/catch can't wrap callbacks

`try/catch` only catches synchronous throws (and awaited rejections) — an error thrown inside a plain callback later on the event loop escapes it entirely.
