Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8385097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:34:57+00:00 2026-06-09T17:34:57+00:00

When we make an open/close mechanism for a resource that uses subresources, we have

  • 0

When we make an open/close mechanism for a resource that uses subresources, we have 2 patterns to handle the subresources release in case of error:

1

RESULT Open() {
   RESULT result;
   result = OpenSubResourceA();
   if (result == SUCCESS)
      result = OpenSubResourceB();

   /* Do not handle error case, the convention is that the caller 
    * will call Close whatever the return code of Open is */
   return result;
}

2

RESULT Open() {
   RESULT result;
   result = OpenSubResourceA();
   if (result == SUCCESS)
      result = OpenSubResourceB();

   if (result != SUCCESS)
      ReleaseSubResourceA();

   /* Release A if opening B failed since the convention is 
    * that the caller calls Close only if Open succeeds */

   return result;
}

Of course we can generalize with more than 2 subresources.

What’s your favorite way of doing things ? And why ?

EDIT

Thanks for your inputs. The idea that the main resource shouldn’t be in some intermediate state outside of the Open/Close calls convinced me that #2 is indeed the best solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:34:58+00:00Added an answer on June 9, 2026 at 5:34 pm

    If operation fails, the resource should be in the same state as before the call, so the client can continue using it. It is bad practice to leave resource in indeterminate half-ready state, if some operation has failed. If you can not (do not want to) cleanup and recover from indeterminate state, then resource should be explicitly rendered into error state, e.g. some member like isError() should start returning true

    That is #2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a program to open and close applications you have installed
do i have to open and close session and transcation in each function (make
I am trying to make a function page that will open and close the
I'm trying to make a small program that could intercept the open process of
Is there a way to make an open worksheet close itself if there is
I use OpenOffice through the java API, and make him open the .odt file,
How to make a UIImageView open a URL in Safari when user clicks it?
Just wondering how I can make my app open automatically at login, but make
I am using jQuery, and wish to make certain links open in a new
How do I make preferences dialog to open up on a particular page? Doing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.