Обработка исключений

uses System.SysUtils;

type
  //exception classes descend from
  //Exception, names start with E
  ESimpleException = class(Exception);

  ERecommendExc = class(Exception)
  public
    //Create(Msg) is inherited;
    //add any other members
    ErrorCode: Integer;
    constructor Create(const Msg: string;
      ACode: Integer);
  end;

constructor ERecommendExc.Create(
  const Msg: string; ACode: Integer);
begin
  inherited Create(Msg);
  ErrorCode := ACode;
end;

begin
  try
    raise ERecommendExc.Create('Oops!'42);
  except
    on E: ERecommendExc do
      WriteLn(E.Message', code ',
        E.ErrorCode);
  end;
end.