Skip to main content

ExceptionValue

Struct ExceptionValue 

Source
pub struct ExceptionValue {
    pub type_name: String,
    pub message: String,
    pub cause: Option<Box<Self>>,
    pub args: Vec<Value>,
    pub stamped_line: Option<u32>,
    pub exceptions: Option<Vec<Self>>,
}
Expand description

A runtime exception value that can be raised and caught by user code.

args holds the positional constructor arguments (CPython’s e.args). For exceptions constructed via the user-facing constructor (ValueError('msg')), this is populated from the call args; for internally-raised exceptions (KeyError on dict miss, IndexError on out-of-range subscript) it defaults to empty and exception_attribute.args synthesizes (message,) to match CPython’s auto-arg behaviour.

stamped_line is set by stamp_line at the eval_stmt boundary and rendered ONLY at the Interpreter::execute boundary into the user-facing errorMessage — it is deliberately invisible to str(e) / repr(e) / print(f'{e}') inside the script, so the agent-loop debug suffix doesn’t bleed into user code that catches and inspects exceptions.

Constructed via ExceptionValue::new + the with_* chain — the struct fields are public for the rare consumer that wants to pattern-destructure, but new construction sites should not use struct-literal form.

Fields§

§type_name: String§message: String§cause: Option<Box<Self>>§args: Vec<Value>§stamped_line: Option<u32>§exceptions: Option<Vec<Self>>

Nested exceptions for ExceptionGroup / BaseExceptionGroup (PEP 654).

Implementations§

Source§

impl ExceptionValue

Source

pub fn new(type_name: impl Into<String>, message: impl Into<String>) -> Self

Build the standard <Type>: <message> exception with no cause, no line stamp. The 95% case.

args mirrors CPython’s positional-args behaviour: an empty message yields args == () (matching Exception()), and a non-empty message yields args == (message,) (matching Exception('msg')). Multi-arg constructors and internal raisers that need a non-message arg layout call Self::with_args to override.

Source

pub fn group( type_name: impl Into<String>, message: impl Into<String>, exceptions: Vec<Self>, ) -> Self

Build an ExceptionGroup (or BaseExceptionGroup) with nested exceptions.

Source

pub fn with_cause(self, cause: Self) -> Self

Attach a raise X from Y-style cause.

Source

pub fn with_args(self, args: Vec<Value>) -> Self

Set the constructor args. Used at the call-as-constructor path (ValueError('msg', 'detail')) so e.args reflects the exact values the user passed.

Source

pub fn key_error(key: impl Display) -> Self

KeyError(<key>) — used by every dict/Counter/defaultdict miss. CPython’s KeyError message is the key’s repr.

Source

pub fn index_error(kind: &str) -> Self

IndexError(<kind> index out of range) — CPython varies the wording by container; pass the type-specific kind (list, tuple, string, bytes, range object, deque).

Source

pub fn zero_division_error(message: impl Into<String>) -> Self

ZeroDivisionError(division by zero) — CPython’s canonical wording for 1/0.

Trait Implementations§

Source§

impl Clone for ExceptionValue

Source§

fn clone(&self) -> ExceptionValue

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 Debug for ExceptionValue

Source§

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

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

impl Default for ExceptionValue

Source§

fn default() -> ExceptionValue

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

impl<'de> Deserialize<'de> for ExceptionValue

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 Serialize for ExceptionValue

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

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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, U> ExactFrom<T> for U
where U: TryFrom<T>,

Source§

fn exact_from(value: T) -> U

Source§

impl<T, U> ExactInto<U> for T
where U: ExactFrom<T>,

Source§

fn exact_into(self) -> U

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> OverflowingInto<U> for T
where U: OverflowingFrom<T>,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> RoundingInto<U> for T
where U: RoundingFrom<T>,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> SaturatingInto<U> for T
where U: SaturatingFrom<T>,

Source§

impl<T> ToDebugString for T
where T: Debug,

Source§

fn to_debug_string(&self) -> String

Returns the String produced by Ts Debug implementation.

§Examples
use malachite_base::strings::ToDebugString;

assert_eq!([1, 2, 3].to_debug_string(), "[1, 2, 3]");
assert_eq!(
    [vec![2, 3], vec![], vec![4]].to_debug_string(),
    "[[2, 3], [], [4]]"
);
assert_eq!(Some(5).to_debug_string(), "Some(5)");
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, 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.
Source§

impl<T, U> WrappingInto<U> for T
where U: WrappingFrom<T>,

Source§

fn wrapping_into(self) -> U