Hi guys, my question is if I throw a derived class, can I catch it by using a base class reference parameter? In the link here, it says the a class derived from base exception can be catched by a catch clause with base exception reference. What if other user defined classes?
Many thanks
Jerry
Exceptions In C++
You can and should catch by (const) reference. This is the preferred way, catching by value can slice and also involve calling the exception copy constructor. C++ doesn't really distinguish between user-defined classes in this way.
Yes.
There is nothing special about std::exception (except that it's defined as a part of the standard library).
There is nothing special about std::exception (except that it's defined as a part of the standard library).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement