Pcornel
Automation · Python Automation

Exceptions

Cheat sheet · https://pcornel.dk/topic.php?topic=5261

Back to the Topic

Answer

Python exceptions signal errors and are handled with try/except/else/finally. Catch specific exceptions, such as requests.Timeout, and let unexpected ones surface with a traceback.

Remember

  • Catch specific exceptions like requests.Timeout.
  • finally always runs for cleanup.
  • Let unexpected exceptions show a traceback.

First checks

  • python3 -c 'raise SystemExit(1)'; echo $? — exit codes
  • Specific exception handling (except ValueError) — precision
  • Logging with exc_info — tracebacks

Verify in this order

error → exception → handle or propagate → exit code

Where it usually breaks

Input/desired state → request accepted → job/task terminal status → target object read-back → effective runtime state → original workload → regression/rollback readiness.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5261

Confirmation

Confirm action

Continue?