我要求Delphi原生,而不是Prism(net).
这是我的代码:
raise Exception.Create('some test');
Run Code Online (Sandbox Code Playgroud)
未声明的标识符"例外".
问题出在哪里,如何抛出/引发异常?
And*_*den 67
异常类"Exception"在单元SysUtils中声明.因此,您必须在uses-clause中添加"SysUtils".
uses
SysUtils;
procedure RaiseMyException;
begin
raise Exception.Create('Hallo World!');
end;
Run Code Online (Sandbox Code Playgroud)
Mar*_*rco 11
请记住将SYSUTILS添加到您的使用单位.
我还建议你一个很好的方法来跟踪类别,杂乱的格式和异常的含义:
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
Run Code Online (Sandbox Code Playgroud)
一种简单的使用方法是:
TMyException.RaiseError1(123);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
49981 次 |
最近记录: |