Skip to main content

Error2

Trait Error2 

Source
pub trait Error2: Error {
    // Required methods
    fn backtrace(&self) -> &Backtrace;
    fn backtrace_mut(&mut self) -> &mut Backtrace;
}
Expand description

Core trait extending std::error::Error with backtrace support.

Error2 provides methods to access and modify the error’s backtrace, enabling detailed error propagation tracking across your application.

§Implementation

Typically implemented via #[derive(Error2)] macro:

use error2::prelude::*;

#[derive(Debug, Error2)]
#[error2(display("configuration error"))]
struct ConfigError {
    backtrace: Backtrace,
}

The macro automatically generates the trait implementation and manages the backtrace field.

§Accessing Backtrace

Use the .backtrace() method to access error chain and locations:

if let Err(e) = do_something() {
    println!("{}", e.backtrace().error_message());
}

See Backtrace for details on accessing error information.

Required Methods§

Source

fn backtrace(&self) -> &Backtrace

Returns a reference to the error’s backtrace.

The backtrace contains the complete error chain and location information.

Source

fn backtrace_mut(&mut self) -> &mut Backtrace

Returns a mutable reference to the error’s backtrace.

Used internally by the library to record error propagation locations.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Error2 for Infallible

Source§

fn backtrace(&self) -> &Backtrace

Source§

fn backtrace_mut(&mut self) -> &mut Backtrace

Source§

impl<T: Error2> Error2 for Box<T>

Source§

fn backtrace(&self) -> &Backtrace

Source§

fn backtrace_mut(&mut self) -> &mut Backtrace

Implementors§