Skip to main content

ExcType

Enum ExcType 

Source
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

Source

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:

  • Exception is the base class for all standard exceptions
  • LookupError is the base for KeyError and IndexError
  • ArithmeticError is the base for ZeroDivisionError and OverflowError
  • RuntimeError is the base for RecursionError and NotImplementedError

Returns true if self would be caught by except handler_type:.

Trait Implementations§

Source§

impl Clone for ExcType

Source§

fn clone(&self) -> ExcType

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ExcType

Source§

impl Debug for ExcType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ExcType

Source§

fn default() -> ExcType

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ExcType

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for ExcType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Eq for ExcType

Source§

impl<'_derivative_strum> From<&'_derivative_strum ExcType> for &'static str

Source§

fn from(x: &'_derivative_strum ExcType) -> &'static str

Converts to this type from the input type.
Source§

impl From<ExcType> for &'static str

Source§

fn from(x: ExcType) -> &'static str

Converts to this type from the input type.
Source§

impl FromStr for ExcType

Source§

type Err = ParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<ExcType, <Self as FromStr>::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for ExcType

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ExcType

Source§

fn eq(&self, other: &ExcType) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ExcType

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ExcType

Source§

impl TryFrom<&str> for ExcType

Source§

type Error = ParseError

The type returned in the event of a conversion error.
Source§

fn try_from(s: &str) -> Result<ExcType, <Self as TryFrom<&str>>::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.