An unhandled rejection from a rejected Promise in async code.
When a Promise rejects and there is no `.catch()` handler or `try/catch` around an `await`, the rejection becomes an "unhandled promise rejection". In browsers this shows as a console warning/error; in Node.js it can crash the process.
This happens when: you use `.then()` without a `.catch()`, you use `async/await` without wrapping in `try/catch`, a fetch request fails and you don't handle the network error, or an error is thrown inside a Promise executor without being caught.
1async function fetchUser(id) {2 // If the network fails or server returns 500,3 // this will throw and the rejection will be uncaught4 const response = await fetch(`https://api.example.com/users/${id}`);5 const data = await response.json();6 return data;7}8 9// Called without try/catch — rejection is unhandled10fetchUser(1).then(user => console.log(user));1async function fetchUser(id) {2 try {3 const response = await fetch(`https://api.example.com/users/${id}`);4 if (!response.ok) {5 throw new Error(`HTTP error! status: ${response.status}`);6 }7 const data = await response.json();8 return data;9 } catch (error) {10 console.error("Failed to fetch user:", error.message);11 return null; // or re-throw, or return a default12 }13}14 15// Or when calling with .then():16fetchUser(1)17 .then(user => console.log(user))18 .catch(error => console.error("Error:", error.message));Simulate standard system builds to trigger compiler trace records and track memory crashes locally.
If `fetch()` throws a network error (e.g., offline), the `awaited` call rejects the `fetchUser` async function's returned Promise. The `.then()` only handles the resolved case. Without a `.catch()` or a rejection handler, this becomes an unhandled rejection.