-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathlib.rs
43 lines (31 loc) · 942 Bytes
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
pub mod threads;
pub use threads::*;
pub fn panic_example() {
println!("Hello, world!");
let h = std::thread::spawn(|| {
std::thread::sleep(std::time::Duration::from_millis(1000));
panic!("boom");
});
let r = h.join();
match r {
Ok(r) => println!("All is well! {:?}", r),
Err(e) => println!("Got an error! {:?}", e),
}
println!("Exiting main!")
}
pub fn panic_caught_example() {
println!("Hello, panic_caught_example !");
let h = std::thread::spawn(|| {
std::thread::sleep(std::time::Duration::from_millis(1000));
let result = std::panic::catch_unwind(|| {
panic!("boom");
});
println!("panic caught, result = {}", result.is_err());
});
let r = h.join();
match r {
Ok(r) => println!("All is well! {:?}", r),
Err(e) => println!("Got an error! {:?}", e),
}
println!("Exiting main!")
}