by panic · 8y ago · 0 comments
* No throw: the function will not fail. Full stop.
* Strong exception safety: if the function fails the state of the object(s) is acting on is unchanged. This is similar to transactional atomicity guarantee.
* Basic guarantee. If the function fails the state of the objects is unspecified but valid (i.e. no invariant is violated), but data might be lost.
From the point of view of the caller of course no throw is the most desirable property, the strong and finally basic. Anything less than that (i.e. corruption, leaks, dangling pointers) is considered unacceptable.
Another important insight is realising that exception guarantees have little to do with exceptions and everything to do with postconditions in the return path: for example the same techniques used to guarantee strong safety on the face of exceptions also work to guarantee postconditions on the faceof multiple explicit retun paths.
This might be a great approach for some (plausibly very large) subset of cases, but it can't handle everything.
Also abort sequences are a thing so you can kinda-sorta unfire them (talk about compensating sequence!).
Not in a way that truly solves the problem. Any time you are coordinating multiple actions that are irreversible and may fail, you'll need some contract other than "either your transaction exceeds or everything is rolled back."
True, but you can always offer at least the basic guarantee, and you can always document what you are guaranteeing to the caller.