Can I avoid the copying of object in the following way?
MyClass Obj;
try {
throw &Obj;
}
catch(MyClass *a) {
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If the object is too expensive to copy, it should not be thrown as an exception – full stop. Exception classes should be fairly simple and light-weight. And you should always catch exceptions by reference (probably by const reference) – catching pointers is bad style. So your code should better be written:
In response to your comment, this:
should be an error. But you simply should not be prohibiting copying of classes you want to throw as exceptions – why are you doing this?