Why raising an exception isn't limited to exception class?

Viewed 123

This delphi code is compilable and works as expected.

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.

My question is that why exception handling isn't limited to raise an exception object that is a descendant of class Exception. (I used FastMM in full debug mode to test if this program causes any memory leak - it doesn't.)

0 Answers
Related