Error Handling¶
Goals¶
- Make failure paths explicit and understandable.
- Catch exceptions only where you can recover.
- Preserve error context for debugging.
Guidance¶
- Prefer EAFP where it improves clarity, but keep failure scope tight.
- Catch specific exceptions; avoid blanket catches.
- Batch tasks can isolate per-item failures; pipelines often stop early.
- When re-raising, keep the original context.
Examples¶
EAFP vs LBYL style checks:
Raising and handling a specific error path:
def foo():
# do something
raise Exception("something wrong")
try:
foo()
except Exception as e:
# handle exception
Batch-style call site: