# एसिंक कोड में try/catch — नोड.जेएस

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

> await और Promise chains से एरर पकड़ना।

## await को wrap करना

किसी `async` फ़ंक्शन के अंदर reject हुआ Promise `await` पर throw होता है — इसे `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 कॉलबैक को नहीं पकड़ सकता

`try/catch` केवल सिंक्रोनस throw (और awaited rejection) पकड़ता है — बाद में इवेंट लूप में किसी सादे कॉलबैक के अंदर हुई एरर इससे पूरी तरह बच जाती है।
