Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Foo;
- impl Foo {
- fn cleanup (self: &'_ mut Self)
- {
- panic!("Foo::cleanup({:p})", self);
- }
- }
- struct Struct {
- foo: Foo,
- }
- impl Drop for Struct {
- fn drop (self: &'_ mut Self)
- {
- use ::std::panic;
- let mut foo = panic::AssertUnwindSafe(&mut self.foo);
- match panic::catch_unwind(move || {
- foo.cleanup();
- })
- {
- | Ok(()) => {},
- | Err(err) => {
- eprintln!("{:p}.foo.cleanup() panicked ({err_msg})", self,
- err_msg = if let Some(s) = err.downcast_ref::<String>() {
- s as &dyn ::core::fmt::Display
- } else {
- &""
- },
- );
- },
- }
- }
- }
- fn main ()
- {
- drop(Struct { foo: Foo, });
- println!("Program keeps going");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement