Skip to main content
GameDev.net gamedev.net
🔒 Locked

Exceptions In C++

Started by monkeyboi Oct 20, 2012 at 2:28 PM 1 replies 1.2k views
Original Post
monkeyboi
monkeyboi
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
rip-off
rip-off
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.
Bregma
Bregma
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.