Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > std::auto_ptr a...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 9556 of 9593
Post > Topic >>

std::auto_ptr as exception object

by ejstans <j.l.olsson@[EMAIL PROTECTED] > Apr 28, 2008 at 03:59 PM

{ Multi-posted article. -mod }

Hello,

I am using std::auto_ptr to try to keep ownership of resources
straight. However, I became aware that exception objects must provide
a copy constructor, which made me uncertain of the soundness of
throwing std::auto_ptrs...

It was explained to me that a problem is:

try {
   throw std::auto_ptr<int>(new int(10));
} catch (std::auto_ptr<int> a) {
   throw;
}

If I understood correctly, the re-throw would use the original
exception object, which has lost ownership.
Is there a way to prevent catching by value?
Is catching by reference kosher?
Are there other problems with throwing auto_ptrs?

Thanks.

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]




 5 Posts in Topic:
std::auto_ptr as exception object
ejstans <j.l.olsson@[E  2008-04-28 15:59:32 
Re: std::auto_ptr as exception object
nickf3 <nickf3@[EMAIL   2008-04-28 23:25:59 
Re: std::auto_ptr as exception object
ejstans <j.l.olsson@[E  2008-04-29 10:36:59 
Re: std::auto_ptr as exception object
nickf3 <nickf3@[EMAIL   2008-04-29 12:43:22 
Re: std::auto_ptr as exception object
"Alf P. Steinbach&qu  2008-04-30 10:42:04 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed May 14 6:44:52 CDT 2008.