So, since that meeting I’ve given this a lot of thought and have definitely weakened from the rather strong position I took at the time. Nonetheless, to clarify: this is not about that case, it’s about the case where you call a destructor normally and then initiate unwinding from within the destructor.
TL;DR I think we should do what C++ does or something very close to it, whatever it is.
In general I have the impression that there are sort of two reasonable things to do when a destructor panics (whether or not you are already unwinding, imo) and both of them have their place:
- Abort eagerly. One way to do this in a (relatively) cost-free way would be to initiate unwinding but to have the landing pad in any destructor abort. This will cause it to abort…eventually.
- Best-effort recovery. How I see it, there is kind of a tree of destructors to run, with a spine rooted in the stack frames / local variables but with children extending down into each field and so forth. If a destructor panics, it seems reasonable to skip that node but keep unwinding as best you can.
The problem with option 2 is that
(a) depending on how hard we work at it, it may have performance costs;
(b) no matter what, something is almost certainly going to leak, maybe a lot (at minimum, the dtor that panics failed to complete, and if that is e.g., a smart pointer, then its referent may not be dropped either);
© particularly in the recursive case, the C++ machinery is not setup to accommodate it.
I can easily imagine applications for which leaking is preferable to aborting, and I can also easily imagine applications for which slight performance costs may be acceptable.
But to be honest I think at the end of the day, as I said in the TL;DR, this is not an area where it is worth innovating. We should try to match the behavior of C++ with reasonable fidelity – if nothing else it will make integrating with C++ codebases easier (though I’ve never worked on one that actually used C++ exceptions…) and allow us to reuse more machinery and so forth. I need to do some research (and haven’t) on the precise behavior of C++ in the various cases.
Well, that’s roughly the current state of my thoughts.