Macro trackable::track_panic [−][src]
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).replace('\\', "/"), r#" Failed HISTORY: [0] at src/macros.rs:10 "#); let e = foo(|| track_panic!(Failed, "something {}", "wrong") ).err().unwrap(); assert_eq!(format!("\n{}", e).replace('\\', "/"), r#" Failed (cause; something wrong) HISTORY: [0] at src/macros.rs:17 "#);