Why does the Base
catch
handler catch a Derived
object, as in:
#include <iostream>
using namespace std;
class Base {};
class Derived: public Base {};
int main()
{
Derived d;
try {
throw d;
}
catch(Base b)
{
cout << "Caught Base Exception";
}
catch(...)
{
cout << "Default
";
}
return 0;
}
The output I get is "Caught Base Exception". I was expecting "Default".
See Question&Answers more detail:os