bug-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem exception handling g++ 2.95.3-i686


From: IT Staff
Subject: Problem exception handling g++ 2.95.3-i686
Date: Tue, 06 Nov 2001 19:00:43 +0100

Hi 

The extest.cpp attachment was missing.

Regards,
IT Staff
#include<stdlib.h>
#include<stdio.h>
#include<string.h>

#define D(s) printf("[%08x]::",(int)this);puts(s);fflush(stdout)

#define EXCEPTION EX

// Ok
//
//#define THROWABLE TR

// Exception
//
#define THROWABLE SB

class T
 {
  int t;
 
  public:
  
  T() { D("T()->"); t=rand()|1; D("<-T()");}
  T(const T& x) { D("T(x)->");t=x.t; D("<-T(x)");}
  ~T() {  D("~T()->");t=0; D("<-~T()"); }
  
  virtual void shadow()
   {
    printf("@1=%p\n",this);
   }
  
  virtual void t_()
   {
    printf("t=%i\n",t);
   }
 };


class TR:public virtual T
 {
  int tr;
 
  public:
  
  TR() { D("TR()->"); tr=rand()|1; D("<-TR()");}
  TR(const TR& x) { D("TR(x)->");tr=x.tr; D("<-TR(x)");}
  ~TR() {  D("~TR()->");tr=0; D("<-~TR()"); }
  
  virtual void who()
   {
    printf("@1=%p\n",this);
   }
  
  virtual void dump()
   {
    who();
    printf("tr=%i\n",tr);
   }
 };

class SB:public virtual T
 {
  int sb;
 
  public:
  
  SB() { D("SB()->"); sb=rand()|1; D("<-SB()");}
  SB(const SB& x) { D("SB(x)->");sb=x.sb; D("<-SB(x)");}
  ~SB() {  D("~SB()->");sb=0; D("<-~SB()"); }
  
  virtual void what()
   {
    printf("@3=%p\n",this);
   }
  
  virtual void show()
   {
    printf("sb=%i\n",sb);
   }
 };


class EX:public TR,public SB
{
 int ex;

 public:
 
 EX() {  D("EX()->");ex=rand()|1;  D("<-EX()");}
 EX(const EX& x):TR(x),SB(x) {  D("EX(x)->");ex=x.ex;  D("<-EX(x)");}
 ~EX() {  D("~EX()->");ex=0;  D("<-~EX()");}
 
 virtual void who()
   {
    printf("@2=%p\n",this);
   }

 virtual void dump()
   {
    TR::dump();
    show();
    printf("ex=%i\n",ex);
   }
};

void exception_test()
 {
  
  puts("exception_test() begin");fflush(stdout);
 
  try
   {
    throw EXCEPTION();
   }
  catch(EX & eErr)
   {
    
    puts("got the throw");fflush(stdout);
    
    throw(eErr);
   }
  
  puts("exception_test() end");fflush(stdout);
 }

int main(){

  puts("test start");fflush(stdout);
  
  try
   {
    exception_test();
   }
  catch(THROWABLE & eErr)
   {
    puts("got it");fflush(stdout);
    
   }

  puts("test done");fflush(stdout);

}


reply via email to

[Prev in Thread] Current Thread [Next in Thread]