1

Possible Duplicate:
Delphi Exception Handling - How to clean up properly?
Use of Try/Finally/Catch Together in Delphi

I would like to know which is the best way to put try-except-finally in delphi? What I mean is in nested try block, which statement should come inside, for example, Example 1

// initialize / allocate resource (create objects etc.)
...
try
     try
        // use resource
        ...
     except
       // handle exception
       ...
     end;
finally
   // free resource / cleanup
   ...
end

Example 2

    // initialize / allocate resource (create objects etc.)
...
try
     try
        // use resource
        ...
     finally
       // free resource / cleanup           
       ...
     end;
except       
   // handle exception
   ...
end

Which is the best way to handle an exception in Delphi, Example 1 or Example 2. why?

Community
  • 1
  • 1
Able Alias
  • 3,824
  • 11
  • 58
  • 87
  • 4
    You get your answer here: http://stackoverflow.com/questions/4155944/use-of-try-finally-catch-together-in-delphi. – az01 Sep 20 '11 at 07:23
  • I'm coding as in your first example. Creating, using the resource, handle any exception, free the resource. also you can check here: http://stackoverflow.com/questions/2922995/should-i-put-a-try-finally-block-after-every-object-create – RBA Sep 20 '11 at 07:23

0 Answers0