www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/06/19/06:18:02

Xref: news2.mv.net comp.os.msdos.djgpp:5153
From: Eric NICOLAS <nicolas AT dsys DOT ceng DOT cea DOT fr>
Newsgroups: comp.os.msdos.djgpp
Subject: Pbs with C++ exceptions [again, URGENT]
Date: Wed, 19 Jun 1996 08:43:02 +0200
Organization: Commissariat a l'energie atomique
Lines: 122
Message-ID: <31C7A176.4A38@dsys.ceng.cea.fr>
NNTP-Posting-Host: hudson.ceng.cea.fr
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hi djgpp gurus !

Using: djgpp v2, first non-beta release

I have some problems with C++ exceptions handling. First if I compile
a C++ program (for example test.cc) which use try/throw/catch, the
compiler answers that exception handling is disable and that I must
use -fhandle-exceptions to enable it. This flag is not documented
in the info files for gcc. strange.

Then If I have two exceptions classes A and B, with B deriving from
A, I should be able to catch exceptions B with a catch(A), no ? (I read
that in the strousup's book).

Someone told me to use a reference cathing (i.e. catch(A&)), but I
got the same result.
Even more strange : I managed to compile test.cc with microsoft's
visual C++, and It worked as expected. So I must be missing one option
for djgpp compiler.

Please help me, it us URGENT !!!!!!!

So here is a simple test program I wrote :

----- test.cc ----------------------------------------------
#include <stdlib.h>
#include <stdio.h>

class CException {};
class CSpecialException : public CException {};
class CAnotherException : public CException {};

void terminate()
{ }

int main()
{       // --- CSpecialException
        puts("Test : Throwing a CSpecialException...");
        puts("-> Should catch the CSpecialException.");
        try {
                throw CSpecialException();
        }
        catch(CSpecialException)
        {       puts("CSpecialException catched");
        }
        catch(CException)
        {       puts("CException catched");
        }
        catch(...)
        {       puts("Other exception catched");
        }
        // --- CException
        puts("\nTest : Throwing a CException...");
        puts("-> Should catch the CException.");
        try {
                throw CException();
        }
        catch(CSpecialException)
        {       puts("CSpecialException catched");
        }
        catch(CException)
        {       puts("CException catched");
        }
        catch(...)
        {       puts("Other exception catched");
        }
        // --- CAnotherException
        puts("\nTest : Throwing a CAnotherException...");
        puts("-> Should catch the CException.");
        try {
                throw CAnotherException();
        }
        catch(CSpecialException)
        {       puts("CSpecialException catched");
        }
        catch(CException)
        {       puts("CException catched");
        }
        catch(...)
        {       puts("Other exception catched");
        }
}
-----------------------------------------------------------

I compiled it with "gcc -x c++ -fhandle-exceptions test.cc -o test".

As strousup said, the result should be :
> Test : Throwing a CSpecialException...
> -> Should catch the CSpecialException.
> CSpecialException catched
>
> Test : Throwing a CException...
> -> Should catch the CException.
> CException catched
>
> Test : Throwing a CAnotherException...
> -> Should catch the CException.
> CException catched

But it is in fact :
> Test : Throwing a CSpecialException...
> -> Should catch the CSpecialException.
> CSpecialException catched
>
> Test : Throwing a CException...
> -> Should catch the CException.
> CException catched
>
> Test : Throwing a CAnotherException...
> -> Should catch the CException.
> Other exception catched
                        <======= ??????

Does anybody have an explanation ???

Thanks.
-- 
Eric Nicolas <nicolas AT dsys DOT ceng DOT cea DOT fr>

Take a look to the SWORD home page :
	france:	http://bunny.ensea.fr/Pages_Perso/Cedric_Joulain/sword.web/home.html
	us:	http://www.iquest.net/~cworley/sword.web/home.html

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019