Creating Custom Exception
Creating Custom Exception
Creating Custom Exception
It's simple:
type
EMyException = Class(Exception)
Private
FErrorCode : Integer;
public
constructor Create(const Msg: String; ErrorCode: Integer);
property ErrorCode: Integer read FErrorCode;
end;
constructor EMyException.Create(const Msg: String; ErrorCode: Integer);
begin
inherited Create(Msg);
FErrorCode:=ErrorCode;
end;
try
if SomethingIsWrong then raise EMyException.Create('Oops', 123);
except
on E: EMyException do ShowMessage(IntToStr(E.ErrorCode));
Didn't try this, but should work. Ask here again if something is wrong.