Delphi Error – E2093 Label ‘%s’ is not declared in current procedure

Delphi Compiler Error

E2093 Label ‘%s’ is not declared in current procedure

Reason for the Error & Solution

In contrast to standard Pascal, Borland’s Delphi language does not allow a goto to jump out of the current procedure.

However, his construct is mainly useful for error handling, and the Delphi language provides a more general and structured mechanism to deal with errors: exception handling.

program Produce;

label 99;

procedure MyProc;
begin
  (*Something goes very wrong...*)
  goto 99;
end;

begin
  MyProc;
  99:
    Writeln('Fatal error');
end.

The example above tries to halt computation by doing a non-local goto.

program Solve;

uses SysUtils;

procedure MyProc;
begin
  (*Something goes very wrong...*)
  raise Exception.Create('Fatal error');
end;

begin
  try
    MyProc;
  except
    on E: Exception do Writeln(E.Message);
  end;
end.

In our solution, we used exception handling to stop the program. This has the advantage that we can also pass an error message. Another solution would be to use the standard procedures Halt or RunError.

Share:

Leave A Reply

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

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...