Как сделать так, чтобы обработка исключений пропускалась через несколько блоков catch в одном случае?

Let's say you have the following hierarchy. You have a base class Animal, with a bunch of sub classes like Cat, Mouse, Dog, etc.

Now, we have the following scenario:

void ftn()
{
   throw Dog();
}

int main()
{
   try
   {
       ftn();
   }
   catch(Dog &d)
   {
    //some dog specific code
   }
   catch(Cat &c)
   {
    //some cat specific code
   }
   catch(Animal &a)
   {
    //some generic animal code that I want all exceptions to also run
   }
}

So, what I want is that even if a Dog is thrown, I want the Dog catch case to execute, and also the Animal catch case to execute. How do you make this happen?

6
задан Chris 16 April 2011 в 00:37
поделиться