Quiero utilizar JCLDebug para registrar todas las excepciones planteadas, incluidas las que se manejan.¿Hay alguna forma de detectar todas las excepciones (incluso las tratadas) con JCLDebug?
¿Es posible hacer eso?
Quiero utilizar JCLDebug para registrar todas las excepciones planteadas, incluidas las que se manejan.¿Hay alguna forma de detectar todas las excepciones (incluso las tratadas) con JCLDebug?
¿Es posible hacer eso?
Eche un vistazo a JclAddExceptNotifier
en la unidad JclHookExcept
.
No está basado en JCL, pero es de código abierto completo y funciona desde Delphi 5 hasta XE.
Este logging mechanism es capaz de interceptar cualquier excepción.
De hecho, desde Delphi 6, se puede definir un procedimiento global en RtlUnwindProc ser inicializado cuando se levanta ninguna excepción:
{$ifdef DELPHI5OROLDER}
procedure RtlUnwind; external kernel32 name 'RtlUnwind';
{$else}
var
oldUnWindProc: pointer;
{$endif}
procedure SynRtlUnwind(TargetFrame, TargetIp: pointer;
ExceptionRecord: PExceptionRecord; ReturnValue: Pointer); stdcall;
asm
pushad
cmp byte ptr SynLogExceptionEnabled,0
jz @oldproc
mov eax,TargetFrame
mov edx,ExceptionRecord
call LogExcept
@oldproc:
popad
pop ebp // hidden push ebp at asm level
{$ifdef DELPHI5OROLDER}
jmp RtlUnwind
{$else}
jmp oldUnWindProc
{$endif}
end;
oldUnWindProc := RTLUnwindProc;
RTLUnwindProc := @SynRtlUnwind;
Este código se lanzará la siguiente función:
type
PExceptionRecord = ^TExceptionRecord;
TExceptionRecord = record
ExceptionCode: DWord;
ExceptionFlags: DWord;
OuterException: PExceptionRecord;
ExceptionAddress: PtrUInt;
NumberParameters: Longint;
case {IsOsException:} Boolean of
True: (ExceptionInformation : array [0..14] of PtrUInt);
False: (ExceptAddr: PtrUInt; ExceptObject: Exception);
end;
GetExceptionClass = function(const P: TExceptionRecord): ExceptClass;
const
cDelphiExcept = $0EEDFAE0;
cDelphiException = $0EEDFADE;
procedure LogExcept(stack: PPtrUInt; const Exc: TExceptionRecord);
begin
LastError := GetLastError;
(...) intercept the exception
SetLastError(LastError); // code above could have changed this
end;
Para Delphi 5, I had to patch the VCL in-process, porque no hay un interceptor de excepción global.
+1, interesante –
Muy interesante, gracias por su respuesta! –
Las últimas versiones admiten plataformas XE4/XE5 y Win32/Win64. –
Gracias hombre, esto me ayuda mucho. También busqué en Google este http://andremussche.blogspot.com/2007/09/adv-debugging-hook-all-exceptions.html –
@Melaum: Eso es probablemente muy interesante, pero desafortunadamente no hablo alemán. (O si eso no es alemán, sea lo que sea, tampoco hablo de eso.) –
no es alemán, es holandés. – jpfollenius