This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Troubles with exception specification
- To: <rysio at rumcajs dot chemie dot uni-halle dot de>
- Subject: Re: Troubles with exception specification
- From: Martin von Loewis <loewis at informatik dot hu-berlin dot de>
- Date: Thu, 5 Nov 1998 10:26:14 +0100
- Cc: egcs-bugs at cygnus dot com, egcs at cygnus dot com
>> 2. The call of B::func should throw `bad_exception', but it doesn't!
Thanks for your bug report. After closer inspection, and several
discussions, this is what I found:
In section 14.6.3 of "The C++ programming language", Stroustrup
explains that adding bad_exception to the exception specification will
activate the "exception mapping", which means that exceptions not
listed in the specification will be mapped to bad_exception by the
implementation.
In section 15.5.2 of the C++ Standard, paragraph 2 explains that such
mapping is performed only if unexpected throws or rethrows, which it
doesn't do by default (18.6.6.2).
Mr Stroustrup confirms that this is a contradiction between his book
and the adopted standard. He maintains that the standard should have
specified such exception mapping, and has brought this issue before
the standards committee
(http://www.research.att.com/~bs/3rd_issues.html).
egcs currently implements the standards behaviour and not Stroustrup's
description. I'd propose that this is remains unchanged until a
decision is made by ISO.
Please note that you can work-around this discrepancy. Just define an
unexpected_handler:
#include <exception>
void my_unexpected()
{
throw std::bad_exception();
}
int main()
{
std::set_unexpected(my_unexpected);
//more code
}
Hope this helps,
Martin
P.S. Even though this came up the first time, I propose to add it to
the FAQ ("Why does bad_exception not work?") or as a non-bug to the
"Known bugs list".