System.SysUtils.EConvertError

From RAD Studio API Documentation
Jump to: navigation, search

System.SysUtils.ExceptionSystem.TObjectEConvertError

Delphi

EConvertError = class(Exception);

C++

class PASCALIMPLEMENTATION EConvertError : public Exception

Properties

Type Visibility Source Unit Parent
class public
System.SysUtils.pas
System.SysUtils.hpp
System.SysUtils System.SysUtils

Description

EConvertError is the exception class for string and object conversion errors.

EConvertError is raised when:

  • An application makes an unsuccessful attempt to convert an integer, float, date, or time to a string, or to convert a string to one of these other types.
  • An application passes an invalid argument to a formatting routine.
  • An application attempts to assign one type of component derived from TPersistent to another component derived from TPersistent when such an assignment is not possible. For example, EConvertError is raised by the attempted assignment of a TButton control to a TEdit control.

In the examples below, an EConvertError exception is raised on the attempt to convert a String to a TDateTime and the date in the String is invalid. The type of exception and the error message are displayed.

//Delphi example

const
  LF = #10;
var
  TempDate: TDateTime;
begin
  try
    TempDate := StrToDateTime('99/99/1998');
  except
    on E: EConvertError do
      ShowMessage(E.ClassName + LF + E.Message);
  end;
end;
//C++ example

TDateTime TempDate;
try
{
  TempDate = StrToDateTime("99/99/1998");
}
catch (EConvertError &E)
{
  ShowMessage(AnsiString(E.ClassName()) + "\n" + AnsiString(E.Message));
}

See Also

Code Examples