pub enum ExcType {
Show 55 variants
Exception,
BaseException,
SystemExit,
KeyboardInterrupt,
ArithmeticError,
OverflowError,
ZeroDivisionError,
LookupError,
IndexError,
KeyError,
RuntimeError,
NotImplementedError,
RecursionError,
AttributeError,
FrozenInstanceError,
NameError,
UnboundLocalError,
ValueError,
UnicodeDecodeError,
UnicodeEncodeError,
JsonDecodeError,
TomlDecodeError,
ImportError,
ModuleNotFoundError,
OSError,
FileNotFoundError,
FileExistsError,
IsADirectoryError,
NotADirectoryError,
PermissionError,
UnsupportedOperation,
TimeoutError,
AssertionError,
MemoryError,
StopIteration,
SyntaxError,
TypeError,
RePatternError,
BinasciiError,
BinasciiIncomplete,
CsvError,
DecimalException,
DecimalClamped,
DecimalInvalidOperation,
DecimalConversionSyntax,
DecimalDivisionByZero,
DecimalDivisionImpossible,
DecimalDivisionUndefined,
DecimalInexact,
DecimalInvalidContext,
DecimalRounded,
DecimalSubnormal,
DecimalOverflow,
DecimalUnderflow,
DecimalFloatOperation,
}Expand description
Python exception types supported by the interpreter.
Uses strum derives for automatic Display, FromStr, and Into<&'static str> implementations.
The string representation matches the variant name exactly (e.g., ValueError -> “ValueError”),
except where a serialize attribute gives a dotted name to disambiguate a stdlib subclass from
its builtin parent (binascii.Error from ValueError, say).
ExcType::VARIANTS is the canonical list of those names, and the host bridges mirror it:
PYTHON_EXC_NAMES in crates/monty-js/ts/errors.ts and the ExcType literal in
pydantic_monty/__init__.py. Both are hand-written, so monty-proto’s exc_type_bridges test
reads them and pins them here — adding a variant without wiring the bridges fails that test.
Variants§
Exception
primary exception class - matches any exception in isinstance checks.
Also the Default — required so Type (which embeds an ExcType in
its Exception variant) can derive strum::EnumIter.
BaseException
System exit exceptions
SystemExit
KeyboardInterrupt
ArithmeticError
Intermediate class for arithmetic errors.
OverflowError
Subclass of ArithmeticError.
ZeroDivisionError
Subclass of ArithmeticError.
LookupError
Intermediate class for lookup errors.
IndexError
Subclass of LookupError.
KeyError
Subclass of LookupError.
RuntimeError
Intermediate class for runtime errors.
NotImplementedError
Subclass of RuntimeError.
RecursionError
Subclass of RuntimeError.
AttributeError
FrozenInstanceError
Subclass of AttributeError (from dataclasses module).
NameError
UnboundLocalError
Subclass of NameError - for accessing local variable before assignment.
ValueError
UnicodeDecodeError
Subclass of ValueError - for encoding/decoding errors.
UnicodeEncodeError
Subclass of ValueError - for encoding errors (e.g. str.encode('ascii')
on a string containing non-ASCII characters).
JsonDecodeError
Subclass of ValueError for invalid JSON syntax in json.loads().
TomlDecodeError
Subclass of ValueError for invalid TOML in tomllib.loads() / tomllib.load().
ImportError
Import-related errors (module not found, name not in module).
ModuleNotFoundError
Subclass of ImportError - for when a module cannot be found.
OSError
OS-related errors (file not found, permission denied, etc.)
FileNotFoundError
Subclass of OSError - for when a file or directory cannot be found.
FileExistsError
Subclass of OSError - for when a file already exists.
IsADirectoryError
Subclass of OSError - for when a path is a directory but a file was expected.
NotADirectoryError
Subclass of OSError - for when a path is not a directory but one was expected.
PermissionError
Subclass of OSError - for when an operation is not permitted (e.g., writing to a read-only mount, or attempting to access a path outside a mounted directory).
UnsupportedOperation
io.UnsupportedOperation - raised by file objects when a requested
operation isn’t allowed by the open mode (e.g. read() on 'w').
In CPython this inherits from both OSError and ValueError. Monty’s
ExcType enum models single parents, but Self::is_subclass_of
matches UnsupportedOperation against both OSError and ValueError
so except ValueError: and except OSError: both catch it as in
CPython.
TimeoutError
Subclass of OSError since Python 3.3 (PEP 3151).
AssertionError
MemoryError
StopIteration
SyntaxError
TypeError
RePatternError
re.PatternError - raised for invalid regex patterns or unsupported regex features.
§Behavior Note
Limited to monty’s exception type, PatternError does not provide pattern, pos,
lineno and colno attributes.
As per CPython’s implementation, it would be hard to convert fancy-regex’s error
representations into the required attributes.
BinasciiError
binascii.Error - raised by the base64 codecs for malformed input.
A ValueError subclass in CPython, so except ValueError: catches it.
BinasciiIncomplete
binascii.Incomplete - a direct Exception subclass, not a ValueError.
Nothing raises it: the a2b_hqx family it belonged to left CPython in
3.11, so the class survives only for except binascii.Incomplete: in
older code. Monty exposes it for the same reason.
CsvError
csv.Error - raised by the csv readers and writers for malformed data
and unknown dialect names.
A direct Exception subclass, named _csv.Error as in CPython.
DecimalException
decimal.DecimalException, the base of every decimal signal.
DecimalClamped
decimal.Clamped: an exponent was changed to fit the representation.
DecimalInvalidOperation
decimal.InvalidOperation: an operation with no meaningful result.
DecimalConversionSyntax
decimal.ConversionSyntax: a malformed numeric string.
DecimalDivisionByZero
decimal.DivisionByZero: a finite non-zero dividend divided by zero.
DecimalDivisionImpossible
decimal.DivisionImpossible: an integer quotient too long for the precision.
DecimalDivisionUndefined
decimal.DivisionUndefined: zero divided by zero.
DecimalInexact
decimal.Inexact: a result was rounded and lost non-zero digits.
DecimalInvalidContext
decimal.InvalidContext: an invalid context setting was detected.
DecimalRounded
decimal.Rounded: a result was rounded, perhaps without losing digits.
DecimalSubnormal
decimal.Subnormal: a result’s exponent fell below Emin.
DecimalOverflow
decimal.Overflow: a result’s exponent exceeded Emax.
DecimalUnderflow
decimal.Underflow: a subnormal result was rounded.
DecimalFloatOperation
decimal.FloatOperation: floats and Decimals were mixed.
Implementations§
Source§impl ExcType
impl ExcType
Sourcepub fn is_subclass_of(self, handler_type: Self) -> bool
pub fn is_subclass_of(self, handler_type: Self) -> bool
Checks if this exception type is a subclass of another exception type.
Implements Python’s exception hierarchy for try/except matching:
Exceptionis the base class for all standard exceptionsLookupErroris the base forKeyErrorandIndexErrorArithmeticErroris the base forZeroDivisionErrorandOverflowErrorRuntimeErroris the base forRecursionErrorandNotImplementedError
Returns true if self would be caught by except handler_type:.
Sourcepub fn decimal_ancestors(self) -> &'static [Self]
pub fn decimal_ancestors(self) -> &'static [Self]
Every base of a decimal exception below Exception, in CPython’s MRO order;
empty for every other type.
The decimal signals inherit from several classes at once (DivisionByZero is
also a ZeroDivisionError, Underflow is Inexact, Rounded and Subnormal).