Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

throw exceptions ....

Posted on 2003-10-27
3
Medium Priority
?
346 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 1

Accepted Solution

by:
fsign21 earned 150 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

722 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