Expand description
A context-aware concrete Error type built on std::error::Error
§Examples
use exn::Exn;
use exn::Result;
use exn::ResultExt;
// using `thiserror` is unnecessary but convenient
use thiserror::Error;
// Errors can enumerate variants users care about
// but notably don't need to chain source/inner error manually.
#[derive(Debug, Error)]
enum AppError {
#[error("serious app error: {consequences}")]
Serious { consequences: &'static str },
#[error("trivial app error")]
Trivial,
}
type AppResult<T> = Result<T, AppError>;
// Errors can also be a plain `struct`, somewhat like in `anyhow`.
#[derive(Debug, Error)]
#[error("logic error")]
struct LogicError;
type LogicResult<T> = Result<T, LogicError>;
fn do_logic() -> LogicResult<()> {
Ok(())
}
fn main() -> AppResult<()> {
// `error-stack` requires developer to properly handle
// changing error contexts
do_logic().or_raise(|| AppError::Serious {
consequences: "math no longer works",
})?;
Ok(())
}
Macros§
Structs§
- Exn
- An exception type that can hold an error tree and additional context.
- ExnView
- An immutable view of an exception.
Traits§
- Context
Bound - A trait to bound the context type of
Exn
. - Error
Bound - A trait to bound the error type of
Exn
. - IntoExn
- A trait to convert a value into an
Exn
(exception) type. - Result
Ext - An extension trait for
Result
to provide context information onExn
s. - Visitor
- A trait for visiting an exception.
Type Aliases§
- Result
- A reasonable return type to use throughout an application.