Performance: Promise catch for async errors
MEDIUM IMPACT
This concept affects how asynchronous errors are handled without blocking the event loop or causing unhandled promise rejections.
async function fetchData() { try { const response = await fetch('https://api.example.com/data'); const data = await response.json(); return data; } catch (error) { console.error('Fetch failed:', error); return null; } } fetchData();
async function fetchData() { const response = await fetch('https://api.example.com/data'); const data = await response.json(); return data; } fetchData(); // No catch or error handling
| Pattern | Error Handling | Event Loop Impact | Process Stability | Verdict |
|---|---|---|---|---|
| No .catch() on Promise | None | Unhandled rejection may crash process | May crash process | [X] Bad |
| Using .catch() on Promise | Proper | Keeps event loop free | Stable process | [OK] Good |
| Async/await without try/catch | None | Unhandled rejections possible | Unstable | [X] Bad |
| Async/await with try/catch | Proper | Stable event loop | Stable process | [OK] Good |