]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/panics/panic-recover-propagate.rs
0a15417f72a4e808379388d29e039b49c1431b9c
[rust.git] / src / test / run-pass / panics / panic-recover-propagate.rs
1 // run-pass
2 // ignore-emscripten no threads support
3
4 use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
5 use std::panic;
6 use std::thread;
7
8 static A: AtomicUsize = ATOMIC_USIZE_INIT;
9
10 fn main() {
11     panic::set_hook(Box::new(|_| {
12         A.fetch_add(1, Ordering::SeqCst);
13     }));
14
15     let result = thread::spawn(|| {
16         let result = panic::catch_unwind(|| {
17             panic!("hi there");
18         });
19
20         panic::resume_unwind(result.unwrap_err());
21     }).join();
22
23     let msg = *result.unwrap_err().downcast::<&'static str>().unwrap();
24     assert_eq!("hi there", msg);
25     assert_eq!(1, A.load(Ordering::SeqCst));
26 }