HomeDelphiDelphi Error – E2126 Cannot BREAK, CONTINUE or EXIT out of a FINALLY clause

Delphi Error – E2126 Cannot BREAK, CONTINUE or EXIT out of a FINALLY clause

Delphi Compiler Error

E2126 Cannot BREAK, CONTINUE or EXIT out of a FINALLY clause

Reason for the Error & Solution

Because a FINALLY clause may be entered and exited through the exception handling mechanism or through normal program control, the explicit control flow of your program may not be followed. When the FINALLY is entered through the exception handling mechanism, it is not possible to exit the clause with BREAK, CONTINUE, or EXIT – when the finally clause is being executed by the exception handling system, control must return to the exception handling system.

  program Produce;

    procedure A0;
    begin
      try
        (* try something that might fail *)
      finally
        break;
      end;
    end;

    begin
    end.

The program above attempts to exit the finally clause with a break statement. It is not legal to exit a FINALLY clause in this manner.

  program Solve;

    procedure A0;
    begin
      try
        (* try something that might fail *)
      finally
      end;
    end;

    begin
    end.

The only solution to this error is to restructure your code so that the offending statement does not appear in the FINALLY clause.

Share:

Leave a Reply

You May Also Like

Delphi Compiler Error X2421 Imported identifier ‘%s’ conflicts with ‘%s’ in ‘%s’ Reason for the Error & Solution This occurs...
Delphi Compiler Error X2367 Case of property accessor method %s.%s should be %s.%s Reason for the Error & Solution No...
Delphi Compiler Error X2269 Overriding virtual method ‘%s.%s’ has lower visibility (%s) than base class ‘%s’ (%s) Reason for the...