I think with C ++ 11, you can safely allow the suffix()
call to throw. A strict rule is never "never thrown from the destructor", although this is good advice, instead of the rule :
never throw an exception from the destructor when handling another exception
In the destructor, you can now use std::current_exception
, which, I think, checks the "while processing another exception" element of the destructor + exception edit. With this you can do:
~Call_proxy() { if (std::current_exception()) { try { suffix(); } catch(...) {
I’m not sure that this is actually a good idea in practice, but it’s hard for you to handle if it throws another exception during the throw.
Regarding “this is abuse”, I don’t think that this abuse is more than metaprogramming or writing a?b:c
instead of the full-scale if
, if that is the right tool for the job! This does not undermine any language rules, simply exploiting them in accordance with the letter of the law. The real problem is the predictability of the behavior of readers unfamiliar with the code, and long-term maintainability, but the problem is for all projects.
Flexo source share