Solved

throw exceptions ....

Posted on 2003-10-27
3
330 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

809 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