Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Exceptions In C++


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 monkeyboi   Members   -  Reputation: 188

Like
0Likes
Like

Posted 20 October 2012 - 08:28 AM

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

Sponsor:

#2 rip-off   Moderators   -  Reputation: 5034

Like
1Likes
Like

Posted 20 October 2012 - 08:50 AM

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.

#3 Bregma   Members   -  Reputation: 2766

Like
0Likes
Like

Posted 20 October 2012 - 08:51 AM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS