Mail Archives: djgpp/1998/06/16/23:54:41
On Mon, 15 Jun 1998 16:42:29, "Andrew Crabtree"
<andrewc AT rosemail DOT rose DOT hp DOT com> wrote:
> > GCC 2.8.1 does NOT handle exceptions properly.
> This is news to me. Whats wrong with it?
My fault ;) I fixed it.. But it's GCC's fault as well.. Here is an
example:
#include <conio.h>
class xError() {};
class temp1
{
f()
{
temp2 test;
test.f2();
}
}
class temp2
{
f2() throw(xError)
{
throw xError();
}
}
main()
{
temp1 test;
try
{
test.f2()
}
catch (...)
{
printf("error caught!");
}
}
The above case is a perfect example of why my exception handling
wasn't working.. I called f2() which in turn called f().. f() threw
the exception (which is legal since it declared throw(xError) in its
prototype) but when the exception reached f() it didn't find a
throw(xError) in the prototype and stoped there with an "Abort!"
message. This mistake occured because my C++ book didn't explain to me
that "throw(xError)" would have to be on all functions which call
other functions which throw this exception. However, it is up to GCC
to warn me of my syntax error. It does warn me if f() doesn't have
throw(xError) in the prototype, so why doesn't it warn me in f2()'s
case? That was my problem and I think the GCC authors should be
contacted and informed of the "flaw".. However, I don't know who to
contact..
Gili
- Raw text -