Topic: Nested Exception Classes


Author: Xavier Huet <huet@compass-da.com>
Date: 1996/07/01
Raw View
Hi everybody,

I have two classes : Class1WithException, Class2WithException.
Inside each I declare a "Exception" Class and a
"DerivedException".

Class1WithException has a member function which can throw
Class1WithException::DerivedException.
Class2WithException has a member function which can throw
Class2WithException::DerivedException.


class Class1WithException
{
public:
        class Exception
        {
        };

        class DerivedException : public Exception
        {
        };

        // this function can throw
        //Class1WithException::DerivedException
        void functionOfClass1();

        // Others member functions.
        ....

};

class Class2WithException
{
public:
        class Exception
        {
        };

        class DerivedException : public Exception
        {
        };

        // this function can throw
        //Class2WithException::DerivedException
        void functionOfClass2();

        // Others member functions.
        ....
        };
};


and now I want :

Class1WithException obj1 = ...;
Class2WithException obj2 = ...;

try
{
  obj1.functionOfClass1();
  obj2.functionOfClass2();
}
catch(Class1WithException::DerivedException& ex)
{
  // Do my clean-up.
  ...
}
catch(Class1WithException::Exception& ex)
{
  // Do my clean-up.
  ...
}
catch(Class2WithException::DerivedException& ex)  <---- Error
{
  // Do my clean-up.
  ...
}
catch(Class2WithException::Exception& ex)
{
  // Do my clean-up.
  ...
}
catch(...)
{
  // Do my clean-up.
  ...
}

When I compile with SoftBench or VC++ 4.0, I have the following
error :
VC++ -- > error C2314:
'class Class2WithException::NegativeException &' : is caught by
base class ('class Class1WithException::Exception &') on line
<Error Line>

SoftBench --> line <Error Line>: error:
Class2WithException::NegativeException&& will be caught by
Class1WithException::Exception& (1820).


When I compile with SparcWorks, all is OK.

Since I didn't see any limitations neither in the Draft
standard or in the ARM, I guess SparcWorks is right.

Could you confirm that, please ?

____________________________________________________________
Xavier Huet - Software Engineer
COMPASS Design Automation       E-mail : huet@compass-da.com
1865 Lundy Avenue               Tel : (408)433-4880 (x47453)
San Jose, CA 95131              Fax : (408)434-7981
____________________________________________________________

      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]