Embarcadero Delphi Try-finally nested inside try-except


Example

A try-finally block may be nested inside a try-except block.

try
  AcquireResources;
  try
    UseResource;
  finally
    ReleaseResource;
  end;
except
  on E: EResourceUsageError do begin
    HandleResourceErrors;
  end;
end;

If an exception occurs inside UseResource, then execution will jump to ReleaseResource. If the exception is an EResourceUsageError, then execution will jump to the exception handler and call HandleResourceErrors. Exceptions of any other type will skip the exception handler above and bubble up to the next try-except block up the call stack.

Exceptions in AcquireResource or ReleaseResource will cause execution to go to the exception handler, skipping the finally block, either because the corresponding try block has not been entered yet or because the finally block has already been entered.