1

Detailed question :

We are trying to capture the stacktrace (bugreport.txt) using MadExcept in a delphi application where a thread is crashing the application with a fatal error. But MadExcept doesn't print any stacktrace after the application crashes. Any ideas why?

OUR CODE :

procedure TMainForm.WSServerExecute(AContext: TIdContext);
begin
  try
    HTMLExecute(AContext);
  except
    on E: Exception do
    begin
      if not(E is EIdException) then
      begin
        LogData.AddError('HTMLExecute error: ' + E.Message);
        madExcept.HandleException;
      end;
      raise;
    end;
  end;
end;

This procedure is called when the client makes a websocket connection back to the server. This is a thread produced by the Indy TCPServer component. The HTMLExecute function is what reads and writes packets between the client and server. I've wrapped that in a try..except block to catch any exceptions. The LogData line is what records the error to the Error Log and the madExcept line is supposed to create the bugreport.txt file. The Raise line passes the exception back to Indy so that it knows a fatal error occurred and will abort the thread.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
Vinod M
  • 19
  • 2
  • I can not see access-violations or memory-corruption in the question, are the tags still valid? – mjn Aug 26 '13 at 09:17

2 Answers2

8

The reason why madExcept is not handling the exception is because you already caught it with on E:Exception do handling it yourself. Just give madExcept.HandleExcept the exception to handle it:

madExcept.HandleException(etNormal, E);
Uwe Raabe
  • 45,288
  • 3
  • 82
  • 130
  • If I modify the code above by intentionally inserting a divide by zero condition in the try block, madExcept.HandleException records the exception without needing the etNormal, E parameters. – kbriggs Aug 26 '13 at 15:03
0

You could try using RegisterHiddenExceptionHandler(stDontDync). See documentation for more details. In your handler then simply do this:

procedure YourHiddenExceptionHandler(const exceptIntf: IMEException; var handled: boolean);
begin
  handled := false;
end;

The above is a trick to force madexcept to work also with handled exceptions, of course it is risky to use it in production...

UnDiUdin
  • 14,924
  • 39
  • 151
  • 249
  • `of course it is risky to use it in production...` @User193655 please explain why this might be. – rossmcm Jan 09 '16 at 04:10