|
-
December 10th, 2005, 08:34 AM
#7
Re: Cleaning up after an exception
 Originally Posted by John E
Is there a better strategy?
Not really. All the possibilities have been mentioned in the thread, but none of them are "better". IMHO, this is one of the biggest design flaws in C++. Ideally, the language should have a construct such as this...
Code:
{
// ....
char* p = new char[100];
AddFinalizer {
delete[] p;
}
// rest of function
}
with the semantics that the finalizer should be called regardless of how the function exits. Unfortunately, it doesn't.
You can use __try/__finally around the whole function body as long as you don't use C++ try/catch and you don't have local variables with destructors in the same function. This is Windows-specific, but since the forum is about Visual C++, I guess that's ok Even the __try/__finally construct is pretty awkward because it forces you to indent the whole function body.
Last edited by googler; December 10th, 2005 at 09:12 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|