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
Windowsunit defines theTExceptionRecordtype.The
SysUtilsunit setsExceptClsProcto a function that maps all the Windows exceptions to appropriate Delphi exceptions, e.g.,Status_Integer_OverflowbecomesEIntOverflow.
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, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access