Failing well.
THE PRINCIPLE
Anticipate what can fail, and decide what should happen.
WHAT CAN FAIL
Files missing or unreadable Network requests Data in an unexpected format Conversions External services
HOW TO HANDLE IT
Catch the specific failure you expect, and respond to it.
WHAT NOT TO DO
Catch every possible error indiscriminately.
WHY NOT
It hides genuine bugs, including ones you would want to know about.
WHAT TO CATCH
The specific error types you can actually handle.
WHAT TO DO WHEN YOU CANNOT HANDLE SOMETHING
Let it propagate, or raise something more meaningful.
WHAT TO NEVER DO
Silence an error and continue as though nothing happened.
That produces wrong results rather than visible failures.
WHAT TO LOG
Enough to diagnose: what failed, with what input, and when.
WHAT TO RAISE FOR YOUR OWN FAILURES
A clear error with a useful message.
WHAT TO CLEAN UP
Files, connections and resources, whether or not an error occurred.