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

Your email address will not be published. Required fields are marked *

You May Also Like

Delphi Compiler Error E2313 Attribute – Known attribute cannot specify properties Reason for the Error & Solution No further information...
Delphi Compiler Error E2379 Virtual methods not allowed in record types Reason for the Error & Solution No further information...
Rodrigo , one of the long time Delphi Developer has been working on one of his personal project “Delphi IDE...