From: Cristian A. <ac...@po...> - 2002-10-11 13:11:14
|
Oscar Fuentes wrote: >Seems the compilers are right: > >>From 15.4/8: >Whenever an exception is thrown and the search for a handler (15.3) >encounters the outermost block of a function with an >exception-specification, the function unexpected() is called (15.5.2) >if the exception-specification does not allow the exception. > >>From 15.4/9 >The function unexpected() may throw an exception that will satisfy the >exception-specificationfor which it was invoked, and in this case the >search for another handler will continue at the call of the function >with this exception-specification(see 15.5.2), or it may call >terminate(). > >Finally, from 15.5.2/2: > >The unexpected() function shall not return, but it can throw (or >re-throw) an exception. If it throws a new exception which is allowed >by the exception specification which previously was violated, then the >search for another handler will continue at the call of the function >whose exception specification was vio-lated. If it throws or rethrows >an exception that the exception-specificationdoes not allow then the >follow-ing happens: If the exception-specificationdoes not include the >class std::bad_exception (18.6.2.1) then the function terminate() is >called, otherwise the thrown exception is replaced by an >implementation-defined object of the type std::bad_exception and the >search for another handler will continue at the call of the function >whose exception-specificationwas violated. > > > Thanks for the pointers, now I got it :) Here is the correct code sample: #include <exception> #include <iostream> void f() throw(int, std::bad_exception) { std::cout << "Throw a char" << std::endl; throw '0'; } void handler() { std::cout << "Handler - retrowing the same char"; throw; } int main() { std::set_unexpected(handler); try { f(); } catch(const std::bad_exception& be) { std::cout << "Caught a bad_exception" << std::endl; } } Cheers, Cristian. |