Built-in Exceptions
Exceptions which Python may raise during a program’s execution.
Beginning with Python 1.5, all built-in exceptions are classes. Prior to
1.5, they were strings; to force string exceptions for backward
compatibility, use the -X
command-line option flag. Class exceptions are mostly indistinguishable
from strings, unless concatenated.
Base Classes (Categories)
ExceptionRoot superclass for all exceptions.
StandardErrorSuperclass for all other built-in exceptions; a subclass of the
Exceptionroot class.ArithmeticErrorSuperclass for
OverflowError,ZeroDivisionError,FloatingPointError; subclass ofStandardError.LookupErrorSuperclass for
IndexError,KeyError; subclass ofStandardError.
Specific Exceptions
AssertionErrorRaised when an assert statement’s test is false.
AttributeErrorOn attribute reference or assignment failure.
EOFErrorImmediate end-of-file hit by input( ) or raw_input( ).
FloatingPointErrorWhen a floating-point operation fails.
IOErrorI/O or file-related operation failure.
ImportErrorOn failure of import to find module or attribute.
IndexErrorOn out-of-range sequence offset (fetch or assign).
KeyErrorOn reference to non-existent mapping key (fetch).
KeyboardInterruptOn user entry of the interrupt key (often Ctrl-C).
MemoryErrorOn recoverable memory exhaustion.
NameErrorOn failure to find a local or global unqualified name.
OverflowErrorOn excessively large arithmetic operation.
RuntimeErrorObsolete catch-all; define a suitable error instead.
SyntaxErrorOn parser encountering ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access