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
impl ExceptionValue
Sourcepub fn new(type_name: impl Into<String>, message: impl Into<String>) -> Self
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.
Sourcepub fn group(
type_name: impl Into<String>,
message: impl Into<String>,
exceptions: Vec<Self>,
) -> Self
pub fn group( type_name: impl Into<String>, message: impl Into<String>, exceptions: Vec<Self>, ) -> Self
Build an ExceptionGroup (or BaseExceptionGroup) with nested exceptions.
Sourcepub fn with_cause(self, cause: Self) -> Self
pub fn with_cause(self, cause: Self) -> Self
Attach a raise X from Y-style cause.
Sourcepub fn with_args(self, args: Vec<Value>) -> Self
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.
Sourcepub fn key_error(key: impl Display) -> Self
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.
Sourcepub fn index_error(kind: &str) -> Self
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).
Sourcepub fn zero_division_error(message: impl Into<String>) -> Self
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
impl Clone for ExceptionValue
Source§fn clone(&self) -> ExceptionValue
fn clone(&self) -> ExceptionValue
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ExceptionValue
impl Debug for ExceptionValue
Source§impl Default for ExceptionValue
impl Default for ExceptionValue
Source§fn default() -> ExceptionValue
fn default() -> ExceptionValue
Source§impl<'de> Deserialize<'de> for ExceptionValue
impl<'de> Deserialize<'de> for ExceptionValue
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl !RefUnwindSafe for ExceptionValue
impl !UnwindSafe for ExceptionValue
impl Freeze for ExceptionValue
impl Send for ExceptionValue
impl Sync for ExceptionValue
impl Unpin for ExceptionValue
impl UnsafeUnpin for ExceptionValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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