EConvertError is the exception class for string and object conversion errors.
EConvertError = class(Exception);
class EConvertError : public Exception;
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;
//C++ example
TDateTime TempDate; try { TempDate = StrToDateTime("99/99/1998"); } catch (EConvertError &E) { ShowMessage(AnsiString(E.ClassName()) + "\n" + AnsiString(E.Message)); }
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|