[Overview][Constants][Types][Classes][Index] Reference for unit 'ptc' (#ptc)

TPTCError.Create

Creates an error object with a specified error message.

Declaration

Source position: line 0

public constructor TPTCError.Create;

constructor TPTCError.Create(

  const AMessage: String

);

constructor TPTCError.Create(

  const AMessage: String;

  const AError: TPTCError

);

constructor TPTCError.Create(

  const AError: TPTCError

);

Arguments

AMessage

  

The error message.

Arguments

AMessage

  

The error message.

AError

  

The compounding error.

Arguments

AError

  

The compounding error.

Description

Creates an error object.

When called without arguments, the error message of the created object is initialized to ''. When AMessage is specified, an error object is created with an error message of AMessage. Here is an example of typical use:

{ do something ... }
failure := DoSomething;

{ check failure }
if failure then
begin
  { error message }
  raise TPTCError.Create('do something failed');
end;

When both AMessage and AError are specified as arguments, the error object is created with the text message and the error object message compounded. The AMessage parameter is the first line of the error message, a newline is inserted in the string, and the error object message is added to the end. Here is an example of typical use:

try
  { do something low level... }
  failure := DoSomethingLowLevel;

  { check failure }
  if failure then
  begin
    { error message }
    raise TPTCError.Create('low level failure');
  end;
except
  on error: TPTCError do
  begin
    { error message }
    raise TPTCError.Create('high level failure', error);
  end;
end;

The error message constructed in the except block has a compound message of 'high level failure'+newline+'low level failure'.