SysUtils.ERangeError

From RAD Studio VCL Reference
Jump to: navigation, search

Contents

Delphi Information

From SysUtils.pas

ERangeError = class(EIntError)


Unit: SysUtils

Type: class

Inherited Class Members: SysUtils.ERangeError Members

C++ Information

From SysUtils.hpp

ERangeError = class(EIntError)


Unit: SysUtils

Type: class

Inherited Class Members: SysUtils.ERangeError Members

Class Constructors & Destructors: SysUtils.ERangeError Constructors

Description

ERangeError is the exception for Delphi range errors.


ERangeError occurs in Delphi code when range checking is enabled and an ordinal value goes outside its declared range.

Note:  Range checking is not a C++ feature. However, ERangeError can occur when C++ code calls Delphi code.
Note:  By default, the Delphi compiler disables range checking. The compiler can always detect obvious range errors, which prevents the following code from compiling.

//Delphi subrange example

var SmallValue: 1..3; SevenBits: byte; begin; SmallValue := 4; //Won't compile: constant expression out of bounds SevenBits := 256; //Won't compile: constant expression out of bounds

end;

Note:  However, the compiler can't anticipate out-of-range values provided at run time:

//Delphi subrange example

var SmallValue: 1..3; SevenBits: byte; ThirtyTwoBits: Integer begin; ThirtyTwoBits := 4; SmallValue := ThirtyTwoBits; //Assigns 4 to SmallValue (SmallValue is stored as a Byte) ThirtyTwoBits := 256; SevenBits := ThirtyTwoBits; //Assigns 0 to ThirtyTwoBits (high-order bits discarded)

end;

Note:  If range checking is enabled, both out-of-bounds assignments throw ERangeError exceptions. To enable range checking, use the Project option in the IDE or the $R+ directive.
Note:  Range checking is considered a debugging feature. It produces bigger and slower executables.
Note:  Do not confuse ERangeError with ERangeException, which relates to errors using graduated controls in VisualULX.

See Also

Personal tools
Translations
Newest Version