Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
fullstack ruleP2universalStack: TypeScript
error-handlingcontrol-flowreadability
Don't throw an error only to catch it yourself one line later
If you handle a failure in the same function, log and return/produce the fallback directly instead of throwing into your own try/catch.
PR: hegnar-ws · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | try { |
| 2 | if (response.status !== 200) throw new Error('Failed: ' + response.status); |
| 3 | } catch (e) { |
| 4 | logger.error(e); |
| 5 | return ''; |
| 6 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | if (response.status !== 200) { |
| 2 | logger.error(`Failed to fetch data. Status: ${response.status}`); |
| 3 | return null; |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)