为什么引发异常不仅限于异常类?

时间:2018-10-24 07:15:39

标签: delphi exception-handling

此delphi代码是可编译的,并且按预期工作。

program RaiseLabel;

uses FastMM4, Windows, StdCtrls;

function CreateLabel(const S: string): TLabel;
begin
  Result := TLabel.Create(nil);
  Result.Caption := S;
end;

begin
  try
    raise CreateLabel('Strange exception example');
  except
    on L: TLabel do begin
      MessageBox(0, PChar(L.Caption), 'TLabel', MB_OK);
    end;
  end;
end.

我的问题是,为什么不将异常处理限制为引发作为Exception类的后代的异常对象。 (我在完全调试模式下使用FastMM来测试该程序是否引起任何内存泄漏-不会。)

0 个答案:

没有答案
相关问题