11 ms·
> Catching panics is correct only in extremely niche scenarios. Catching panics is correct when the panic would cause unwinding across a FFI boundary. I can't
by SAI_Peregrinus 2y ago
> Catching panics is correct only in extremely niche scenarios.
Catching panics is correct when the panic would cause unwinding across a FFI boundary. I can't think of anywhere else where I wouldn't be very suspicious seeing a catch_unwind().
- int_19h 2y agoA good example of valid use of catch_unwind() would be for a desktop app to try to save a copy of any unsaved in-memory state before it crashes for good. Since invariants are already broken, it might or might not work, and may possibly save some garbage data, but it is much better than saving nothing at all. The one common thing for all such patterns is that they happen at or near the topmost layer of the app (e.g. around the main loop for GUI apps, or around the request handler for web apps).