How to raise exceptions in Delphi?
You are using SysUtils aren't you? Exception is declared in there IIRC.
Remember to add SysUtils
to your uses
units.
I also suggest below a nice way to keep track of categories, formats of messages and meaning of exception:
Type TMyException=class
public
class procedure RaiseError1(param:integer);
class procedure RaiseError2(param1,param2:integer);
class procedure RaiseError3(param:string);
end;
implementation
class procedure TMyException.RaiseError1(param:integer);
begin
raise Exception.create(format('This is an exception with param %d',[param]));
end;
//declare here other RaiseErrorX
A simple way of using this is:
TMyException.RaiseError1(123);
The exception class "Exception" is declared in the unit SysUtils. So you must add "SysUtils" to your uses-clause.
uses
SysUtils;
procedure RaiseMyException;
begin
raise Exception.Create('Hallo World!');
end;
You may need to add sysutils to the uses clause, it is not built in and is optional according to Delphi in a nutshell.