Xref: news2.mv.net comp.os.msdos.djgpp:5075 From: Eric NICOLAS Newsgroups: comp.os.msdos.djgpp Subject: Pbs with C++ exceptions Date: Mon, 17 Jun 1996 08:59:59 +0200 Organization: Commissariat a l'energie atomique Lines: 115 Message-ID: <31C5026F.6180@dsys.ceng.cea.fr> NNTP-Posting-Host: hudson.ceng.cea.fr Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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). So here is a simple test program I wrote : ----- test.cc ---------------------------------------------- #include #include 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 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