no-unreachable-catch
ProDead CodeDisallow try/catch blocks where the try body contains no code that can throw
no-unreachable-catch
Disallow try/catch blocks where the try body contains no code that can throw
Category: Dead Code | Tier: Pro
Why This Matters
AI wraps safe operations in try/catch blocks defensively. When the try block cannot throw, the catch block is dead code that misleads readers into thinking the operation is risky and adds unnecessary complexity.
Bad Code
// Catch block can never execute -- JSON.stringify doesn't throw
try {
const str = JSON.stringify({ name: 'test' });
} catch (error) {
console.error('Failed to stringify', error);
}
Good Code
// Only wrap operations that can actually throw
const str = JSON.stringify({ name: 'test' });
// Use try/catch for operations that genuinely fail
try {
const data = JSON.parse(userInput);
} catch (error) {
console.error('Invalid JSON input', error);
}
Configuration
This rule has no configuration options. It is enabled by default in lintmyai:recommended.