pub enum ExcType {
Show 37 variants
Exception,
BaseException,
SystemExit,
KeyboardInterrupt,
ArithmeticError,
OverflowError,
ZeroDivisionError,
LookupError,
IndexError,
KeyError,
RuntimeError,
NotImplementedError,
RecursionError,
AttributeError,
FrozenInstanceError,
NameError,
UnboundLocalError,
ValueError,
UnicodeDecodeError,
UnicodeEncodeError,
JsonDecodeError,
ImportError,
ModuleNotFoundError,
OSError,
FileNotFoundError,
FileExistsError,
IsADirectoryError,
NotADirectoryError,
PermissionError,
UnsupportedOperation,
TimeoutError,
AssertionError,
MemoryError,
StopIteration,
SyntaxError,
TypeError,
RePatternError,
}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”).
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().
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.
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:.