Sign in to follow this  

C++ and "finally"

This topic is 4863 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does C++ (standard or non-standard) have support for try..finally blocks? I'm running gcc 3.3.2 and thought it had support for "__finally" but it doesn't seem to. Anyone?

Share this post


Link to post
Share on other sites
I've looked for it before but couldn't find it. I believe the idea is to use objects and their destructors to handle what the finally block would do otherwise. Although it can be kind of annoying to have to wrap everything into an object to be able to handle it.

Share this post


Link to post
Share on other sites
Quote:
Original post by Agony
I've looked for it before but couldn't find it. I believe the idea is to use objects and their destructors to handle what the finally block would do otherwise. Although it can be kind of annoying to have to wrap everything into an object to be able to handle it.


The techniques are called initialization is resource acquisition & resource acquisition is initialization

Share this post


Link to post
Share on other sites
Ok, I was trying to match a possible problem in Delphi, where basically a function would return a value even if a an exception occurred during that function because of an optimization Borland does. It works the same way in Borland C++'s __finally, although MSVC++ behaves as you would expect it to. I really did need finally to compare the behavior. Thanks for all the posts, though.

Share this post


Link to post
Share on other sites

This topic is 4863 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this