Description
If I create an extern "C"
function which will call a method on some other type and that function triggers a panic, is it enough to just wrap the call with std::panic::catch_unwind()
and translate it to an error code?
My thinking is that the object could be messed up internally and I should use poisoning to make sure it can never be accessed again, which was my solution in Michael-F-Bryan/thin-trait-objects#2.
But all unsafe
code should already ensure it won't trigger UB in the face of panics so exception safety is already guaranteed and further poisoning is overkill... isn't it? Or should unsafe
code be overly conservative and try to protect users from implementations which are accidentally not Maximally Exception Safe, to use the terminology from the nomicon?
I feel like my options are to,
- Add a
W: UnwindSafe
bound toFileHandle::for_writer()
(which isn't overly ergonomic because lots of types are!UnwindSafe
) and just wrap panicking calls instd::panic::catch_unwind()
, allowing people to have logic errors or bugs when they try to use the object later on - Skip the
UnwindSafe
bound and neuter/poison theFileHandle
the moment a panic occurs
(original question was asked in Michael-F-Bryan/thin-trait-objects#1)