rust/tests/ui/panics/panic-recover-propagate.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

28 lines
645 B
Rust
Raw Normal View History

//@ run-pass
//@ needs-unwind
//@ ignore-emscripten no threads support
2019-01-26 16:14:49 +00:00
use std::sync::atomic::{AtomicUsize, Ordering};
2015-12-25 19:00:40 +00:00
use std::panic;
use std::thread;
2019-01-26 16:14:49 +00:00
static A: AtomicUsize = AtomicUsize::new(0);
2015-12-25 19:00:40 +00:00
fn main() {
panic::set_hook(Box::new(|_| {
2015-12-25 19:00:40 +00:00
A.fetch_add(1, Ordering::SeqCst);
}));
2015-12-25 19:00:40 +00:00
let result = thread::spawn(|| {
let result = panic::catch_unwind(|| {
2015-12-25 19:00:40 +00:00
panic!("hi there");
});
panic::resume_unwind(result.unwrap_err());
2015-12-25 19:00:40 +00:00
}).join();
let msg = *result.unwrap_err().downcast::<&'static str>().unwrap();
2015-12-25 19:00:40 +00:00
assert_eq!("hi there", msg);
assert_eq!(1, A.load(Ordering::SeqCst));
}