async function saveData(data) {
try {
const result = await api.post('/save', data);
return result;
} catch (err) {
console.log('Error:', err);
}
}
// Caller
const result = await saveData(data);
if (result) updateUI(result); // silently fails on errorasync function saveData(data) {
try {
const result = await api.post('/save', data);
return result;
} catch (err) {
console.error('Error saving data:', err);
throw err; // re-throw so caller can handle it
}
}
// Caller
try {
const result = await saveData(data);
updateUI(result);
} catch (err) {
showErrorMessage(err);
}Bug: The catch block logs but doesn't re-throw. The function returns undefined on error. Caller can't distinguish success from failure.
Explanation: Catching an error and not re-throwing it silently swallows it. The function returns undefined and callers can't tell what happened. Always re-throw or return an error indicator.
Key Insight: If you catch an error and don't re-throw it, callers are flying blind. Only catch if you can truly handle it.