System.ExceptObject
Delphi
function ExceptObject: TObject;
C++
extern DELPHI_PACKAGE TObject* __fastcall ExceptObject(void);
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
function | public | System.pas System.hpp |
System | System |
Description
Returns the current exception object.
ExceptObject returns the current exception object. This is the Exception object that represents the exception currently being handled. If no exception is currently being handled, ExceptObject returns nil (Delphi) or NULL (C++).
ExceptObject is useful when the exception variable (declared in the Delphi on block or C++ catch statement) is not accessible. This can occur when the exception handler calls a procedure, putting the is exception variable out of scope. This is also true in the Delphi else exception handler, which cannot declare an exception variable.
Note: The object returned by ExceptObject may not exist after the exception handler finishes. Thus, you cannot use ExceptObject to retain a reference to the exception object, or to raise the exception again. If you need to do either of these things, call AcquireExceptionObject.
Note: ExceptObject works for C++ only when the exception raised is a Delphi-style exception. To correctly use ExceptObject for C++, for Delphi-style exceptions, use a code similar to the following:
#include <System.SysUtils.hpp>
#include <stdio.h>
int main()
{
try
{
StrToInt("bad integer");
}
catch(...)
{
TObject* Obj = ExceptObject();
printf("ExceptObject=%s\n", Obj ? AnsiString(Obj->ClassName()).c_str() : "NULL");
}
}
See Also
Code Examples