
Peter Dimov wrote:
Alexander Terekhov:
Avoiding unwinding for unexpected exceptions, for example.
The reason the standard specifies calling unexpected() at the exception spec point is conceptually sound (but practically not that useful). Consider
void f() { throw X(); }
void g() throw(Y) { f(); }
void h() throw(Z) { g(); }
If unexpected() is always invoked at the throw point, there is no way for an exception to escape this call stack. If it's invoked at the exception specification points, it can, in principle, first throw a Y, then a Z. The primary purpose of unexpected(), as originally envisaged (I presume), is exception translation.
But exception translation can be done much more sensibly without unexpected(). void f() { throw X(); } void g() throw(Y) { translate_any_exception_to<Y>(f); } void h() throw(Z) { translate_exception<Y, Z>(g); } No? regards, alexander.