Mail Archives: djgpp/1997/02/01/20:57:08
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 -