MadExcept for delphi is not printing stacktrace after application crash

1k views Asked by At

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.

2

There are 2 answers

1
UnDiUdin On

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...

1
Uwe Raabe On

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);