异常处理

uses System.SysUtils,
  System.Generics.Collections;

type
  EIsNilException = class(Exception);
  EIsEmptyException = class(Exception);

procedure ThrowWhenNilOrEmpty(
  List: TList<Integer>);
begin
  if List = nil then
    raise EIsNilException.Create('is nil');
  if List.Count = 0 then
    raise EIsEmptyException.Create('is empty');
end;

var
  List: TList<Integer>;
begin
  List := TList<Integer>.Create;
  try
    ThrowWhenNilOrEmpty(List);
  except
    on EIsNilException do
      WriteLn('list is not specified');
    on EIsEmptyException do
      WriteLn('list is empty');
  end;
  //printed 'list is empty'
end.