Exceptions In C++

Started by
1 comment, last by Bregma 11 years, 6 months ago
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
Advertisement
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).

Stephen M. Webb
Professional Free Software Developer

This topic is closed to new replies.

Advertisement