Uh oh
unknown
rust
a year ago
849 B
12
Indexable
use std::{
any::Any,
panic::catch_unwind,
sync::{Arc, Mutex},
};
fn main() {
let not_done_yet = catch_unwind(|| wat().unwrap());
let _ = catch_unwind(|| {
let x: Box<dyn Any + Send> = Box::new("hi");
print_failure(Err(&x));
});
let grabbled_data = Arc::new(Mutex::new(not_done_yet));
let _ = catch_unwind(|| {
let binding = grabbled_data.as_ref().lock().unwrap();
let x = binding.as_ref();
let y: Result<(), &Box<dyn Any + Send>> = Err(x.err().as_ref().unwrap());
print_failure(y);
});
drop(grabbled_data);
// Now finally blow it up
panic!("poop");
}
fn print_failure(input: Result<(), &Box<dyn Any + Send>>) {
println!("{:?}", input.unwrap())
}
fn wat() -> Result<(), Box<dyn Any + Send>> {
catch_unwind(|| oops().unwrap())
}
fn oops() -> Result<(), String> {
Err("Panic".to_owned())
}Editor is loading...
Leave a Comment