Interview frequency: …
Short answer
Promise errors travel through rejection chains, while outer try/catch blocks fail to catch errors inside traditional callbacks, causing the server to crash.
Explanation
A try/catch block protects only synchronous code executed in the same call stack. If an asynchronous function that accepts a traditional callback is called and an exception is thrown inside it with throw, the original stack has already ended, and the error goes straight to uncaughtException.
Code example
import { readFile } from "node:fs/promises";
const data = await readFile("file.txt");Common mistakes
- Throwing errors with throw inside a regular callback function instead of passing them to the first parameter (err).