www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/01/20:57:08

From: billlanam AT california DOT com (Bill Lanam)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Serious djgpp problem with exceptions ?
Date: Sun, 02 Feb 1997 01:06:46 GMT
Message-ID: <32f3bbc4.53222@seashell.california.com>
References: <32f93129 DOT 6685902 AT news DOT ind DOT mh DOT se>
NNTP-Posting-Host: 140.174.210.125
Lines: 68
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Sat, 01 Feb 1997 12:04:11 GMT, mrkite AT cyberjunkie DOT com (Marco Salvalaggio)
wrote:

>// Except.cc
>//
>//	Testing djgpp exception handling.
>//
>#include <iostream.h>
>#include <string.h>
>
>class MyExcept
>{
>   char msg[80];
>
>public:
>   MyExcept(const char *s) {  strcpy(msg, s); }
>
>   virtual void why() { cout << endl << msg << flush; }
>};
>
>class MyOtherExcept : public MyExcept
>{
>   int dummy;
>
>public:
>   MyOtherExcept( const char *s, int n ) : MyExcept(s), dummy(n) {}
>   void why() { MyExcept::why(); cout << ' ' << dummy << flush; }
>};
>
>void f1();
>void f2();
>
>void main()
>{
>   try
>   {
>      f1();
>   }
>   catch( MyExcept& x )	// This one ok MyExcept thrown, MyExcept catched
>   {
>      x.why();
>   }
>
>   try
>   {
>      f2();
>   }
>   catch( MyExcept& x )	// This one not ok. The program aborts.
if changed to catch '(MyOtherExcept& x)' it then works.

>   {
>      x.why();
>   }
>}
>
>void f1()
>{
>   throw(MyExcept("Error in f1()"));
>}
>
>void f2()
>{
>   throw( MyOtherExcept("Error in f2()", 16) );
>}
>--------------------------------------------------------------------------------------------------


    Bill Lanam

- Raw text -


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