Why does a try/catch miss an error from a promise I did not await?
Quick answer
A normal try/catch catches errors thrown while its block is running. If you start a promise but do not await it, the block can finish before that promise rejects, so the later rejection is not caught there. Use await inside the try block, or attach .catch() to the promise. [S1]
The question, the details, the next step.
A practical checklist
Identify the promise-returning call that can reject.
If the next step needs its result, put
awaitfor that call inside the relevanttryblock.If the operation can run independently, attach
.catch()to its promise chain.Choose a meaningful response for the error instead of leaving an empty handler.
Verify that the handler is attached to the promise or chain that can actually reject.
A few more useful answers
Does putting a promise call anywhere inside `try` make its rejection catchable?
No. A call without await can return a promise that rejects after the synchronous try block has finished. Await it inside the block or attach .catch() to the promise chain. [S1]
Can I use both `await` and `.catch()`?
Either can handle a rejection, but using both for the same operation may make the flow harder to follow. Choose the pattern that fits whether the surrounding function needs to wait for the result.
What does this guide not establish?
It explains how to connect a handler to a promise rejection. It does not establish which recovery behavior, logging approach, or user-facing message is appropriate for a particular application.
Sources
References used for this guide.
- [S1] Using promises — JavaScript | MDN developer.mozilla.org · Checked
