I'm asking for Delphi native, not Prism(net).
This is my code:
raise Exception.Create('some test');
Undeclared identifier "Exception".
Where's the problem, how do I throw/raise exceptions?
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;
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With