Skip to main content

Exception

Struct Exception 

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

An exception instance.

Made by calling a Class, and after that it is an ordinary value until something raises it.

Implementations§

Source§

impl Exception

Source

pub fn new(kind: Kind, args: Vec<Object>) -> Self

An instance of this class with these arguments.

Source

pub const fn kind(&self) -> Kind

Which class it is an instance of.

Source

pub fn args(&self) -> &[Object]

What it was constructed with, which is e.args and is what everything it prints is made out of.

Source

pub fn cause(&self) -> Option<Object>

What it was raised from, if it was raised from anything.

Cloned out rather than borrowed, because the cell it lives in cannot stay borrowed across the walk up a chain of them.

Source

pub fn raised_from(&self, cause: Option<Object>)

Record what this was raised from, which is the from in a raise.

Writing a from at all is what suppresses the context, so raise x from None says “this one, and do not print whatever I happened to be handling”, which is the only way to write that sentence.

Source

pub fn context(&self) -> Option<Object>

What was being handled when this was raised, if anything was.

Cloned out for the same reason Exception::cause is: the cell cannot stay borrowed across the walk up a chain of them.

Source

pub fn suppresses_context(&self) -> bool

Whether a traceback should stop before printing the context.

Source

pub fn message(&self) -> String

What str(e) says, which is the half of a traceback’s last line after the colon.

Three shapes and one exception to them. No arguments says nothing at all, one argument is that argument, and more than one is the tuple of them. KeyError is the one that prints its single argument the way repr would, which is what makes a missing key of '' visible.

Trait Implementations§

Source§

impl Debug for Exception

Source§

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

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

impl Native for Exception

Source§

fn repr(&self) -> String

The class name and the arguments, which is what reads back as the call that would make it again.

Source§

fn truthy(&self) -> bool

Every exception is true, including the ones with no arguments, which is worth saying because an empty tuple is not.

Source§

fn type_name(&self) -> &str

What type(x).__name__ says, which is what error messages need. Read more
Source§

fn display(&self) -> String

What str prints, which for a type with no __str__ of its own is whatever repr prints. Almost every native type wants the default. An exception is the one that does not, because str(e) is the message and repr(e) is the call that would make it again.
Source§

fn as_any(&self) -> &dyn Any

The concrete value, for the runtime to downcast back to.
Source§

fn walking(&self) -> bool

Whether this is already an iterator, meaning iter(x) is x and a for over a half consumed one carries on rather than starting again. Read more
Source§

fn equals(&self, _other: &dyn Native) -> bool

Whether this is equal to another native value that is not the same object as it. Read more
Source§

fn hash(&self) -> Option<i64>

This value’s hash, or nothing to be hashed by address like an object with no __hash__ of its own. 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<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, 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, <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.