Python handles errors with try/except blocks, optional else (runs if no exception) and finally (always runs). Catching specific exceptions makes tests fail clearly and clean up reliably.
Code that might fail goes in try; matching exceptions are caught in except SpecificError as e. Catch the narrowest exception type (except ValueError, not bare except) so you don't hide bugs. else runs only when no exception occurred; finally always runs (cleanup like closing files/drivers). You raise errors with raise ValueError('msg'), and can define custom exceptions (class TestDataError(Exception)). In tests, prefer letting unexpected exceptions propagate (so the test fails loudly) and use try/except only where you genuinely handle or transform an error.
Ensuring a WebDriver quits even if a step fails: try: run_steps() except AssertionError: capture_screenshot(); raise finally: driver.quit() — the browser always closes, and the failure still surfaces.
A teammate wraps a whole test in try/except: pass and it now 'passes' even when broken. Why is this dangerous?