Skip to content

typescript.empty_catch

Correctness High Common in Incidents

Detects empty catch blocks that silently swallow errors.

Empty catch blocks hide real problems:

  • Silent failures — Operations fail with no indication
  • Debugging nightmare — Errors vanish without trace
  • Masked bugs — Logic errors become invisible
  • Data corruption — Failures occur but code continues

Every swallowed error is a bug waiting to surprise you.

// ❌ Before
try {
riskyOperation();
} catch (e) {
}

If riskyOperation fails, you’ll never know.

// ✅ After
try {
riskyOperation();
} catch (error) {
console.error('Unhandled error:', error);
// Or re-throw, or handle specifically
}
  • Empty catch blocks catch (e) {}
  • Catch with only comments
  • Catch that ignores the error parameter

Unfault can add error logging to empty catch blocks when there’s no explicit suppression comment.

// Log and continue (non-critical)
try {
sendAnalytics(event);
} catch (error) {
console.error('Analytics failed:', error);
// Non-critical, continue execution
}
// Log and re-throw (preserve stack)
try {
critical();
} catch (error) {
logger.error('Critical operation failed', { error });
throw error;
}
// Handle specific errors
try {
await fetchData();
} catch (error) {
if (error instanceof NetworkError) {
return cachedData;
}
throw error;
}
// Explicit ignore (document why)
try {
optionalCleanup();
} catch {
// Intentionally ignored: cleanup is best-effort
}