i noticed that when u compile with visual C++ u don't need the throw statement in function headers, but when u compile with g++ u need to explicitly mention all the exceptions u're function might throw.
i mean:

void functionx() throw ( exception1 , exception 2)
{
//blabla
throw exception1;
//blabla
throw exception2;
}

but if u have a base class A and a derived class B, how do u write the throw statement for the B class constructor?
because

B::B() : a() throw ( exception1 , exception2 )
gives the
errorr C2612: trailing 'throw' illegal in base/member initializer list

thx

Recommended Answers

All 2 Replies

struct A
{
  A( int i ) throw(char,int,double) : value(i) {}
  int value ;
};

struct B : A
{
  B() throw(char,int,double) ;
};

B::B() throw(char,int,double) : A(20) {}
commented: Nice +3
struct A
{
  A( int i ) throw(char,int,double) : value(i) {}
  int value ;
};

struct B : A
{
  B() throw(char,int,double) ;
};

B::B() throw(char,int,double) : A(20) {}

thx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.