Swallowing Errors with Empty Catch
You'll learn why catching errors without doing anything with them creates invisible failures that are nearly impossible to debug.
The Silent Killer of Debugging
When you wrap an await call in a try/catch block but leave the catch block completely empty, you're swallowing the error. The error occurs, gets caught, and then... vanishes. Your code continues as if nothing happened, but something did happen—you just threw away all evidence of it.
async function fetchUserData(id) {
let userData;
try {
userData = await fetch(`/api/users/${id}`);
} catch (error) {
// Empty catch block - error disappears here!
}
return userData; // Might be undefined, no idea why
}
In this example, if the fetch fails, the error gets caught and discarded. The function returns undefined with no explanation. You'll spend hours wondering why userData is undefined, checking the API, your network, your parameters—when the real issue was a network timeout or 404 that you intentionally hid from yourself.
Why This Destroys Debugging
Errors contain crucial information: what went wrong, where it happened, and often why. An empty catch block is like having a fire alarm that silences itself instead of alerting you. Future you (or your teammates) will have zero clues about what failed.
Always do something in a catch block:
- Log the error:
console.error(error) - Re-throw it:
throw error - Return a default value and log:
console.warn(error); return null; - Handle it specifically based on error type
Key Takeaway: Never use an empty catch block—every caught error should be logged, re-thrown, or explicitly handled with context, otherwise you're hiding critical debugging information from yourself.