Name
ExceptClsProc Variable
Syntax
var ExceptClsProc: Pointer; functionExceptClassProc
(var Rec: TExceptionRecord): TClass; begin ... end; ExceptClsProc := @ExceptClassProc
;
Description
Delphi calls the function that
ExceptClsProc
points to when a Windows exception
occurs inside a try
-except
block that contains exception handlers (that is, where Delphi must
test which exception handler matches the exception raised).
The sole argument to the ExceptClsProc
function is
a pointer to an exception record.
The class that ExceptClsProc
returns must be the
same type as the object that ExceptObjProc
returns. Delphi uses the class from ExceptClsProc
to identify which exception handler to use before it calls
ExceptObjProc
to create the exception object.
Tips and Tricks
The
Windows
unit defines theTExceptionRecord
type.The
SysUtils
unit setsExceptClsProc
to a function that maps all the Windows exceptions to appropriate Delphi exceptions, e.g.,Status_Integer_Overflow
becomesEIntOverflow
.
Example
// Simple example of mapping Windows exceptions to custom exceptions. class CustomException = class(Exception); class CustomMathException = class(CustomException); class CustomRangeException = class(CustomException); function CustomExceptClsFunc(var Ex: TExceptionRecord): TClass; begin case Ex.ExceptionCode of STATUS_ARRAY_BOUNDS_EXCEEDED, STATUS_INTEGER_OVERFLOW: Result := CustomRangeException; STATUS_INTEGER_DIVIDE_BY_ZERO, STATUS_FLOAT_INEXACT_RESULT, STATUS_FLOAT_INVALID_OPERATION, STATUS_FLOAT_STACK_CHECK, ...
Get Delphi in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.