0% found this document useful (0 votes)
52 views1 page

Creating Custom Exception

The document describes how to create a custom exception class in Delphi by inheriting from the Exception class and adding custom properties like an error code.

Uploaded by

Itamar Monteiro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views1 page

Creating Custom Exception

The document describes how to create a custom exception class in Delphi by inheriting from the Exception class and adding custom properties like an error code.

Uploaded by

Itamar Monteiro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

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.

You might also like