12.1.1.4 floating-point exceptions
Floating-point exceptions are generated when real operations are performed, they all derive from a Ematherror class, but are the same as integer exceptions, and are always raised in its subclasses Einvalidop, Ezerodivide, Eoverflow, Eunderflow.
Table 12.4 Floating-point exception classes and their causes
━━━━━━━━━━━━━━━━━━━━━━━━
Exception class causes
────────────────────────
EINVALIDOP processor ran into an undefined directive
Ezerodivide tried to be 0 apart
Eoverflow Floating point Overflow
Eunderflow floating point underflow
━━━━━━━━━━━━━━━━━━━━━━━━
The most common cause of EINVALIDOP is that a machine without a coprocessor encounters a coprocessor directive. Because Delphi always compiles floating-point operations into coprocessor instructions by default, this error is often encountered on computers under 386. At this point, you only need to set the global compilation instruction {$N-} in the interface portion of the cell, and the problem can be solved by choosing to use the Run-time library for floating-point operations.
The various types of floating-point numbers (real, single, Double, Extended) cross borders cause the same overflow exception. This is different from the integer exception class.
12.1.1.5 Type Match exception
Type matching exception einvalidcast when an attempt is made to match an object with a different class of objects using the as operator.
12.1.1.6 Type Conversion exception
Type conversion exception Econverterror is thrown when an attempt is made to convert data from one form to another using a conversion function, especially if a string is converted to a numeric value. The two execution statements in the following program will throw a Econverterror exception.
Var
Rl:real;
Int:integer;
Begin
RL: = Strtofloat (' $140.48 ');
int: = Strtoint (' 1,402 ');
End
Be aware that not all type conversion functions throw econverterror exceptions. For example, the function Val returns only the error code when it cannot complete the conversion of a string to a numeric value. Using this we implemented the type and range checking of input in section (6.2).
12.1.1.7 Hardware exception
There are two types of hardware anomalies: either the processor detects an error it cannot handle, or the program produces an interrupt that attempts to abort the execution of the program. Hardware exceptions cannot be compiled into a dynamic-link library (DLLs) and can only be used in standard applications.
Hardware exceptions are subclasses of the Eprocessor exception class. However, the runtime does not throw a Eprocessor exception.
Table 12.5 Hardware Exception classes and why they occur
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Exception class causes
─────────────────────────────────
Efault basic Exception class. is the parent class of other exception classes
Egpfault General protection error. Usually caused by an uninitialized pointer or object
Estackfault illegal access to processor stack segment
Epagefault Windows Memory Manager does not use swap files correctly
The Einvalidopcode processor encountered an undefined directive. This usually means that the processor
Attempting to manipulate illegal data or uninitialized memory
Ebreakpoint application produces a breakpoint interrupt
Esinglestep application produces a single step interrupt
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Efault and egpfault often mean fatal mistakes. Ebreakpoint and Esinglestep are handled by the Delphi IDE's built-in debugger. In fact, the response and handling of the five hardware anomalies that are in front of them is a tricky problem for developers.