← Lab 4

Errors — staying in control

Catch it & carry on
  • ▸Read a traceback — the last line names the error
  • ▸try: … except KeyError: … carry on
  • ▸Catch the specific type, not a bare except:
Raise & survive
  • ▸raise ValueError("that isn't DNA") on bad input
  • ▸Your own error types: class NotDNAError(ValueError)
  • ▸A batch job that records failures and keeps going
Python for Biologists