Hook all exceptions lazarus / 62-General ---------------------------------------------------------------------- DevilDevil · 2020-10-13 17:06 Starting from Delphi 2009, it became possible to catch all exceptions through the RaiseExceptObjProc callback, for example, for analysis purposes. In FreePascal, when an exception is raised, the fpc_RaiseException function is called: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Procedure fpc_RaiseException (Obj : TObject; AnAddr : CodePointer; AFrame : Pointer);[Public, Alias : 'FPC_RAISEEXCEPTION']; compilerproc;var  _ExceptObjectStack : PExceptObject;  _ExceptAddrstack : PExceptAddr;begin{$ifdef excdebug}  writeln ('In RaiseException');{$endif}  if ExceptTryLevel<>0 then    Halt(217);  ExceptTryLevel:=1;  PushExceptObject(Obj,AnAddr,AFrame);  { if PushExceptObject causes another exception, the following won't be executed,    causing halt upon entering this routine recursively. }  ExceptTryLevel:=0;  _ExceptAddrstack:=ExceptAddrStack;  If _ExceptAddrStack=Nil then    DoUnhandledException;  _ExceptObjectStack:=ExceptObjectStack;  if (RaiseProc <> nil) and (_ExceptObjectStack <> nil) then    with _ExceptObjectStack^ do      RaiseProc(FObject,Addr,FrameCount,Frames);  longjmp(_ExceptAddrStack^.Buf^,FPC_Exception);end; I am trying to override RaiseProc function, but the given code is not being called. How to catch all exceptions by analogy with Delphi? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1; {$APPTYPE CONSOLE} uses  SysUtils; procedure MyRaiseProc(Obj: TObject; Addr: CodePointer; FrameCount: Longint; Frame: PCodePointer);begin  Writeln(Obj.ClassName);end; begin  System.RaiseProc := @MyRaiseProc;   try    raise Exception.Create('Message');  except    on E: Exception do    begin    Writeln('Except part');    end;  end;   Write('Press Enter to quit');  Readln;end. ---------------------------------------------------------------------- jamie · 2020-10-13 19:34 The Tapplication has the OnException you can redirect.. ---------------------------------------------------------------------- rvk · 2020-10-13 20:27 Quote from: DevilDevil on October 13, 2020, 07:06:44 pmI am trying to override RaiseProc function, but the given code is not being called. How to catch all exceptions by analogy with Delphi? Does it also catch handled exception in Delphi or only unhandled exception. In your code you handle the exception yourself. What happens if you don't handle the exception or reraise it? ---------------------------------------------------------------------- ASerge · 2020-10-13 22:12 And System.RaiseProc for raise. For catch System.ExceptProc. ---------------------------------------------------------------------- DevilDevil · 2020-10-14 06:40 Quote from: ASerge on October 14, 2020, 12:12:19 amAnd System.RaiseProc for raise. For catch System.ExceptProc. ExceptProc only works if the exception is not caught at all (without try/except). RaiseProc never works. ---------------------------------------------------------------------- PascalDragon · 2020-10-14 09:59 Quote from: DevilDevil on October 13, 2020, 07:06:44 pmI am trying to override RaiseProc function, but the given code is not being called. How to catch all exceptions by analogy with Delphi? Are you per chance testing this on i386-win32 (on 3.2.0+) or x86_64-win64 (on 3.0.0+)? If so then due to the switch to Structured Exception Handling, this is currently not supported and the fpc_RaiseException you showed is not used there. ---------------------------------------------------------------------- DevilDevil · 2020-10-14 11:57 PascalDragon, Very sorry. Thanks