Skip to main content

Panic

Struct Panic 

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

Panic info gathered as one record

Contains panic’s location, message or raw payload, and backtrace, if collected

Implementations§

Source§

impl Panic

Source

pub fn location(&self) -> Option<&OwnedLocation>

Panic location, if original std::panic::PanicHookInfo provided one

Source

pub fn message(&self) -> &str

Original panic message which was supplied to std::panic! macro

If panic was raised using std::panic::panic_any with non-string payload, this function returns substitute message

Source

pub fn raw_payload(&self) -> Option<&Box<dyn Any + Send + 'static>>

Raw panic payload if it wasn’t recognized as string-like message and converted to it

Source

pub fn backtrace(&self) -> &Backtrace

Panic’s backtrace gathered from within panic hook

Source

pub fn into_raw_payload(self) -> Box<dyn Any + Send + 'static>

Transforms panic info into raw panic payload. If it’s a string-like message, it gets re-wrapped again.

Useful when you need something like rethrowing panic

Source

pub fn display_with_backtrace(&self) -> impl Display + '_

Produces std::fmt::Display’able object which displays panic’s message, location and short backtrace, if captured

Source

pub fn display_with_backtrace_style( &self, style: BacktraceStyle, ) -> impl Display + '_

Produces std::fmt::Display’able object which displays panic’s message, location and backtrace, if captured, with specified style

Trait Implementations§

Source§

impl Debug for Panic

Source§

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

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

impl Display for Panic

Source§

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

Displays panic’s message and location

To display full panic info including backtrace, use Panic::display_with_backtrace

Source§

impl Error for Panic

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more

Auto Trait Implementations§

§

impl !Freeze for Panic

§

impl !RefUnwindSafe for Panic

§

impl Send for Panic

§

impl !Sync for Panic

§

impl Unpin for Panic

§

impl UnsafeUnpin for Panic

§

impl !UnwindSafe for Panic

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.