Koskamo

Handling errors and exceptions

Document v1 · published by Koskamo editorial · updated 2026-10-04

Original source

Python distinguishes syntax errors, which the parser flags with arrows pointing at the place where the error was detected, from exceptions, errors detected during execution that are not unconditionally fatal. Handle selected exceptions with try and except: the try clause executes first; if no exception occurs the except clause is skipped, and if one occurs the rest of the try clause is skipped and the except clause runs only when the exception's type matches the one named — otherwise the exception propagates to outer try statements, and with no handler it becomes an unhandled exception that stops execution with an error message. A try statement may have several except clauses, but at most one handler executes, and handlers only see exceptions raised in their own try clause. One clause may name several exceptions, as in except (RuntimeError, TypeError, NameError), and a clause matches instances of the named class or its derived classes, so the first matching clause is triggered; ordering handlers from derived to base classes is Koskamo editorial guidance drawn from that rule. Scope: Python 3. Reviewed October 4, 2026.

Source and provenance

Original source
docs.python.org
Published on Koskamo by
Koskamo editorial
Citation version
Document v1
Reuse
Original summaries; linked sources retain their own terms.

The original source supplies the underlying information. Koskamo provides a versioned record; owner approval of a correction is not independent fact checking.