For the code below, result is "EA Exception Finished", which means although we threw at derived class it caught by base class. Is it always? And if so, how can I make the derived class catches, thus "EB Exception Finished" appears?
Also I can't exactly get what does it mean by throw EB()
and catch(EA&)
. And does catch(EA&)
means the catch block gets a reference for EA object?
Sorry for my ignorance. If you recommend me a book or something to refer about exception structure, that'd be great help.
class EA {};
class EB: public EA {};
void F()
{
throw EB(); // throw at EB().
}
int main()
{
try
{
F();
}
catch(EA&) // caught here??
{
std::cout<<"EA Exception";
}
catch(EB&) // why not me? every time?
{
std::cout<<"EB Exception";
}
std::cout<<" Finished"<<std::endl;
return 0;
}