方法抛出异常

异常处理

uses System.SysUtils;

//任何例程都可能抛出异常:
//签名中没有 "throws"
procedure MethodWithException;
begin
  raise Exception.Create('test exception');
end;

begin
  try
    MethodWithException;
  except
    on E: Exception do
      WriteLn('Error happened: ', E.Message);
  end;
end.