Skip to main content

RawException

Struct RawException 

Source
pub struct RawException { /* private fields */ }
Expand description

An exception caught and detached from the call scratch: the payload is copied once, into storage owned by the value itself, so it survives arbitrary later SDK operations (including re-use of the call scratch). Without alloc that storage is a fixed SCRATCH_MAX-capacity inline buffer, so the value (and any error enum holding it) is roughly 4 KiB; under alloc it is an exact-size heap allocation. Use MapExceptions when a compact classification is enough and the original wire bytes do not need to outlive the call.

Deliberately not encodable: there is no WriteXDR impl. re_throw aborts with the verbatim wire bytes; try_as decodes to a typed exception, with selector / payload for raw inspection.

Implementations§

Source§

impl RawException

Source

pub fn selector(&self) -> u64

Source

pub fn payload(&self) -> &[u8] ⓘ

The exception payload (everything after the selector prefix).

Source

pub fn try_as<T: Exn + ReadXDROwned>(&self) -> Option<T>

Source

pub fn try_decode<T: Exn + ReadXDROwned>(&self) -> Option<Result<T, ReadError>>

Source

pub fn re_throw(&self) -> !

Re-throw to our caller with the original wire bytes, verbatim.

Source

pub fn new(selector: u64, payload: &[u8]) -> Self

Build from a selector and payload. Test/mock construction.

Source

pub fn from_abort_buf(bytes: &[u8]) -> Result<Self, LibraryExn>

Parse an abort wire buffer ([CXS(selector)][payload]) into an owned exception. Host tests and mock plumbing.

Trait Implementations§

Source§

impl Debug for RawException

Source§

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

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

impl From<RawExceptionRef<'_>> for RawException

What RawExceptionRef::to_owned produces: one copy. Any number may be live at once; without alloc each value carries its own fixed SCRATCH_MAX-capacity buffer.

Source§

fn from(exn: RawExceptionRef<'_>) -> Self

Converts to this type from the input type.
Source§

impl MatchExn for RawException

Source§

fn as_exn(&self) -> Option<RawExceptionRef<'_>>

The caught exception, or None if this failure carries none (a fault, an invalid call, an encode/decode failure).
Source§

fn try_as<E: Exn + ReadXDROwned>(&self) -> Option<E>

Decode as E if this failure carries an exception of that type. Read more
Source§

fn try_decode<E: Exn + ReadXDROwned>(&self) -> Option<Result<E, ReadError>>

try_as with the decode failure kept separate: Read more
Source§

impl PartialEq for RawException

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl ReThrow for RawException

Source§

fn re_throw(self) -> !

Re-throw this error. Exceptions are propagated as exceptions; faults panic (a fault stays a fault).

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

Source§

type Output = T

Should always be Self
Source§

impl<T> StaticIfNoAlloc for T

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.