pub fn capture_error<E>(error: &E) -> UuidExpand description
Captures a std::error::Error.
Creates an event from the given error and sends it to the current hub. A chain of errors will be resolved as well, and sorted oldest to newest, as described in the sentry event payloads.
ยงExamples
let err = "NaN".parse::<usize>().unwrap_err();
sentry::capture_error(&err);
assert_eq!(captured_event.exception.len(), 1);
assert_eq!(&captured_event.exception[0].ty, "ParseIntError");Examples found in repository?
examples/health.rs (line 30)
3fn main() {
4 let _sentry = sentry::init(
5 sentry::ClientOptions::new()
6 // release health requires a release to be set
7 .maybe_release(sentry::release_name!())
8 .debug(true)
9 // session tracking is enabled by default, but we want to explicitly
10 // create the session
11 .auto_session_tracking(false),
12 );
13
14 let handle = std::thread::spawn(|| {
15 // this session will be set to crashed
16 sentry::start_session();
17 std::thread::sleep(std::time::Duration::from_secs(3));
18 panic!("oh no!");
19 });
20
21 sentry::start_session();
22
23 sentry::capture_message(
24 "anything with a level >= Error will increase the error count",
25 sentry::Level::Error,
26 );
27
28 // or any error that has an explicit exception attached
29 let err = "NaN".parse::<usize>().unwrap_err();
30 sentry::capture_error(&err);
31
32 std::thread::sleep(std::time::Duration::from_secs(2));
33
34 // this session will have an error count of 2, but otherwise have
35 // a clean exit.
36 sentry::end_session();
37
38 handle.join().ok();
39}