// The following example will disable EurekaLog for all exceptions raised in ntdll, kernel32 and kernelbase DLLs.
uses
EInject;
var
EurekaLogExceptionDispatcher: TExceptionDispatcherProc;
function IgnoreException(const AContext: Windows.TContext; const AExceptionRecord: Windows.TExceptionRecord): Cardinal; stdcall;
const
EXCEPTION_CONTINUE_SEARCH = 0;
cDelphiException = $0EEDFADE; // see System.pas
var
ExceptionAddress: Pointer;
ExceptionModule: HMODULE;
ExceptionModuleFileName: String;
ExceptionModuleName: String;
function IgnoreThisException: Boolean;
begin
Result := SameFileName(ExceptionModuleName, 'ntdll.dll') or
SameFileName(ExceptionModuleName, 'kernel32.dll') or
SameFileName(ExceptionModuleName, 'kernelbase.dll');
end;
begin
if AExceptionRecord.ExceptionCode = cDelphiException then
ExceptionAddress := Pointer(AExceptionRecord.ExceptionInformation[0]) // see System.TExceptionRecord
// Exception object is available in TObject(AExceptionRecord.ExceptionInformation[1])
else
ExceptionAddress := AExceptionRecord.ExceptionAddress;
ExceptionModule := FindHInstance(ExceptionAddress);
ExceptionModuleFileName := GetModuleName(ExceptionModule);
ExceptionModuleName := ExtractFileName(ExceptionModuleFileName);
if IgnoreThisException then
Result := EXCEPTION_CONTINUE_SEARCH // RTL Handler will be called
else
Result := EurekaLogExceptionDispatcher(AContext, AExceptionRecord); // EurekaLog will be called
end;
initialization
EurekaLogExceptionDispatcher := EInject.EventExceptionDispatcher;
EInject.EventExceptionDispatcher := IgnoreException;
end.
Comments
0 B
|👍
/👎
0 B
|👍
/👎