pub fn register_error_hook<F>(callback: F)๐Deprecated since 1.0.0:
register_error_hook silently drops registration failures; use try_register_error_hook instead
Expand description
Register a callback to be called when errors are created.
Deprecated since 1.0.0. This variant silently discards
the registration failure when a hook is already installed.
Use try_register_error_hook instead โ it returns the
failure explicitly so callers can decide how to handle the
double-registration case.
ยงExample
use error_forge::macros::{try_register_error_hook, ErrorLevel};
let _ = try_register_error_hook(|ctx| {
match ctx.level {
ErrorLevel::Debug => println!("DEBUG: {} ({})", ctx.caption, ctx.kind),
ErrorLevel::Info => println!("INFO: {} ({})", ctx.caption, ctx.kind),
ErrorLevel::Warning => println!("WARNING: {} ({})", ctx.caption, ctx.kind),
ErrorLevel::Error => println!("ERROR: {} ({})", ctx.caption, ctx.kind),
ErrorLevel::Critical => println!("CRITICAL: {} ({})", ctx.caption, ctx.kind),
// `ErrorLevel` is `#[non_exhaustive]` โ minor releases
// may add new severity levels.
_ => println!("OTHER: {} ({})", ctx.caption, ctx.kind),
}
});