throwing statement in derived class constructor

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2008
Posts: 119
Reputation: kux is on a distinguished road 
Solved Threads: 10
kux kux is offline Offline
Junior Poster

throwing statement in derived class constructor

 
0
  #1
Jan 30th, 2008
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:
  1. void functionx() throw ( exception1 , exception 2)
  2. {
  3. //blabla
  4. throw exception1;
  5. //blabla
  6. throw exception2;
  7. }
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
Last edited by Ancient Dragon; Jan 30th, 2008 at 7:14 am. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: throwing statement in derived class constructor

 
1
  #2
Jan 30th, 2008
  1. struct A
  2. {
  3. A( int i ) throw(char,int,double) : value(i) {}
  4. int value ;
  5. };
  6.  
  7. struct B : A
  8. {
  9. B() throw(char,int,double) ;
  10. };
  11.  
  12. B::B() throw(char,int,double) : A(20) {}
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 119
Reputation: kux is on a distinguished road 
Solved Threads: 10
kux kux is offline Offline
Junior Poster

Re: throwing statement in derived class constructor

 
0
  #3
Jan 30th, 2008
Originally Posted by vijayan121 View Post
  1. struct A
  2. {
  3. A( int i ) throw(char,int,double) : value(i) {}
  4. int value ;
  5. };
  6.  
  7. struct B : A
  8. {
  9. B() throw(char,int,double) ;
  10. };
  11.  
  12. B::B() throw(char,int,double) : A(20) {}
thx
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC