Macro trackable::track_panic
[−]
[src]
macro_rules! track_panic { ($error:expr) => { ... }; ($error_kind:expr, $($format_arg:tt)+) => { ... }; }
Error trackable variant of the standard panic!
macro.
This returns an TrackableError
object as the result value of the calling function,
instead of aborting the current thread.
Conceptually, track_panic!(error)
is equivalent to the following code:
use trackable::Trackable; use trackable::error::TrackableError; let e = TrackableError::from(error); // Converts to `TrackableError` let e = track!(e); // Tracks this location Err(e)?; // Returns from the current function
Examples
use trackable::error::{Failed, Failure}; fn foo<F>(f: F) -> Result<(), Failure> where F: FnOnce() -> Result<(), Failure> { f() } let e = foo(|| track_panic!(Failed) ).err().unwrap(); assert_eq!(format!("\n{}", e), r#" Failed HISTORY: [0] at <anon>:9 "#); let e = foo(|| track_panic!(Failed, "something {}", "wrong") ).err().unwrap(); assert_eq!(format!("\n{}", e), r#" Failed (cause; something wrong) HISTORY: [0] at <anon>:16 "#);