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
impl Exception
Sourcepub fn new(kind: Kind, args: Vec<Object>) -> Self
pub fn new(kind: Kind, args: Vec<Object>) -> Self
An instance of this class with these arguments.
Sourcepub fn args(&self) -> &[Object]
pub fn args(&self) -> &[Object]
What it was constructed with, which is e.args and is what everything
it prints is made out of.
Sourcepub fn cause(&self) -> Option<Object>
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.
Sourcepub fn raised_from(&self, cause: Option<Object>)
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.
Sourcepub fn context(&self) -> Option<Object>
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.
Sourcepub fn suppresses_context(&self) -> bool
pub fn suppresses_context(&self) -> bool
Whether a traceback should stop before printing the context.
Sourcepub fn message(&self) -> String
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 Native for Exception
impl Native for Exception
Source§fn repr(&self) -> String
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
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
fn type_name(&self) -> &str
type(x).__name__ says, which is what error messages need. Read moreSource§fn display(&self) -> String
fn display(&self) -> String
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 walking(&self) -> bool
fn walking(&self) -> bool
iter(x) is x and a for
over a half consumed one carries on rather than starting again. Read more