Mail Archives: djgpp/1998/06/17/00:22:34
Gili wrote in message ...
: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:
=============
As an example, it seems to not be very good.
Try compiling with -Wall -W -ansi -pedantic and
count the error messages. This is what I get:
a.cc:3: parse error before `('
a.cc:15: warning: all member functions in class `temp1' are private
a.cc:15: semicolon missing after declaration of `temp1'
a.cc: In method `int temp1::f()':
a.cc:9: `temp2' undeclared (first use this function)
a.cc:9: (Each undeclared identifier is reported only once
a.cc:9: for each function it appears in.)
a.cc:9: parse error before `;'
a.cc:10: `test' undeclared (first use this function)
a.cc:11: warning: control reaches end of non-void function `temp1::f()'
a.cc: At top level:
a.cc:-245872: `struct temp2' used prior to declaration
a.cc:22: warning: all member functions in class `temp2' are private
a.cc: In method `int temp2::f2()':
a.cc:18: type `xError' is not yet defined
a.cc:19: warning: control reaches end of non-void function `temp2::f2()'
a.cc: At top level:
a.cc:23: two or more data types in declaration of `main'
a.cc:23: semicolon missing after declaration of `class temp1'
a.cc: In function `int main()':
a.cc:27: no matching function for call to `temp1::f2 ()'
a.cc:28: parse error before `}'
a.cc:31: warning: implicit declaration of function `int printf(...)'
=============
:
:#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 -