Article View: comp.std.c++
Article #3960Re: Must exception classes have copy constructors?
From: Rob Stewart
Date: Mon, 08 Apr 1996 18:44
Date: Mon, 08 Apr 1996 18:44
39 lines
2461 bytes
2461 bytes
Steve Clamage wrote: > > Alan Griffiths <aGriffiths@ma.ccngroup.com> writes: > > >I've just tried porting some code to MSVC4 (it compiles and works with > >SC7.1 and BC4.5). > > >In effect it appears that the Microsoft compiler _requires_ anything > >thrown as an exception to have an accessible copy constructor. (I've > >tended to make copy constructors private to ensure catch-by-reference > >and aviod slicing bugs.) > > According to the draft standard, when you throw something, what is > thrown is actually a copy of that something. If the copy constructor > for that something is not accessible, the copy can't be made. > [snip] > In your case, you will probably have to throw a pointer instead > of a value, if the type has a private copy constructor. You'll have to implement an exception object management policy. (I know the exception is actually the pointer to some class, but I'm using "exception object" to mean the object pointed to by that exception.) You must allocate your exception objects on the heap, and delete them in the final catch block. That is, so long as you throw the pointer up the stack, as it were, you cannot delete what the pointer points to. Only in the catch block in which you no longer rethrow the exception can you delete the memory (exception object) it points to. -- Robert Stewart | My opinions are usually my own. Datalytics, Inc. | stew@datalytics.com --- [ comp.std.c++ is moderated. To submit articles: try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ] [ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ] [ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Technical Details
Message-ID:
<316958BE.28E5@datalytics.com>Path:
arc1-ca.pugleaf.net!in1.uu.net!bounce-backReferences:
<606373375wnr@ma.ccngroup.com> <4k6130$l22@engnews1.Eng.Sun.COM>Show Full Headers
Complete Article Headers
From: Rob Stewart <stew@datalytics.com> Message-ID: <316958BE.28E5@datalytics.com> X-Original-Date: Mon, 08 Apr 1996 14:19:42 -0400 Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back Date: 08 Apr 96 18:44:22 GMT Approved: fjh@cs.mu.oz.au Newsgroups: comp.std.c++ Subject: Re: Must exception classes have copy constructors? Organization: Datalytics, Inc References: <606373375wnr@ma.ccngroup.com> <4k6130$l22@engnews1.Eng.Sun.COM> X-Mailer: Mozilla 2.0 (WinNT; I) X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMWlej+EDnX0m9pzZAQFRigF+J6viPD5FKYOILbFD/iaBh6JCF3aYVS1n qhg4Fc/awej0KnmN4fsf1/Dv/99WXfgg =9ykZ