Given the pseudo-code below, I want to catch the exception thrown by the sub-object a in class B, maintaining this object private in B. The catch clause as stated below doesn’t work because the object a is private in B. How can I catch this exception ?
Edit I have changed the pseudo-code to embed class A within class B.
class B
{
class A
{
public:
class Exception{};
A() throw(Exception) { ... } // A ctor throws an Exception class object
} a;
public:
B() { ... } // B ctor
};
int main()
{
try
{
B b;
}
catch( B::A::Exception& )
{
...
}
}
Add a typedef to the exception in the surrounding class.