Solved

throw exceptions ....

Posted on 2003-10-27
3
324 Views
Last Modified: 2010-04-02
To C++ Experts,
  I got some wired results in the following code :
--------------------------------
class Base{
   public:
     void virtual function() throw(int, double,long) ;
};

class Derived:public Base{
   public :
      void function();  //line 1
//   void function() throw(double, int, long);  // line 2
                                                                //comments tempararily
};
----------------------------------
 If I understand correctly, the exceptions thrown in the Derived class should be at least as restrictive as the Based on. Therefore, I think line1 should not compile .... however, it compiles !!! Is there any reason or did I misunderstand anything here ??? thanks.

 Also, in the line 2, is that okay the orders of exptions are different from the one in base class ? (i.e. throw(double, int, long) instead of
throw(int, double, long) )
Thanks a lot !

meow ....
0
Comment
Question by:meow00
3 Comments
 
LVL 1

Accepted Solution

by:
fsign21 earned 50 total points
ID: 9628484
You understood right: the exceptions thrown in the Derived class should be at least as restrictive as the Based on.
I tried with the Sun 6.0 Compiler and I get a compile error, if I try to compile
class Base{
public:
void virtual function() throw(int) ;
};

class Derived:public Base{
public :
void function();
};

Probably, you have a compiler issue here

0
 
LVL 9

Expert Comment

by:tinchos
ID: 10546193
No comment has been added lately, so it's time to clean up this question.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: fsign21 {http:#9628484}

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now