Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. use std::thread;
  2. use std::panic;
  3.  
  4. pub fn main(){
  5. thread::spawn(move || {
  6. panic::catch_unwind(|| {
  7. // panic!("Oh no! A horrible error.");
  8. let s: Option<u32> = None;
  9. s.expect("Nothing was there!");
  10. })
  11. })
  12. .join()
  13. .and_then(|result| {
  14. match result {
  15. Ok(ref val) => {
  16. println!("No problems. Result was: {:?}", val);
  17. }
  18. Err(ref err) => {
  19. if let Some(err) = err.downcast_ref::<&'static str>() {
  20. println!("Error: {}", err);
  21. } else {
  22. println!("Unknown error type: {:?}", err);
  23. }
  24. }
  25. }
  26. result
  27. });
  28. }
  29.  
  30. Error: Oh no! A horrible error.
  31.  
  32. Unknown error type: Any
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement