Exceptions & try/except
Errors are raised, caught, and handled. Don't swallow exceptions silently.
Code example
try:
result = 10 / x
except ZeroDivisionError as e:
print(f'cannot divide by zero: {e}')
result = None
except Exception:
raise # re-raise anything unexpected
finally:
cleanup()
How it works
Python uses exceptions for error handling. `try` runs code; `except` catches specific exception types; `finally` always runs. The notebook kernel wraps every cell in try/except so a syntax error in one cell doesn't kill the kernel — it just renders the traceback in the output pane and the next cell can still run. FastAPI's exception handlers in main.py catch 404/500/429 and return proper HTML or JSON.
🔍 Where this is used in OpenBenchML
Notebook cell executor, FastAPI exception handlers, model loading in benchmark.py.