Jump to content
Cristian Peța

Messages for exceptions only for main thread?

Recommended Posts

I just realized that exception messages are shown only for main thread. I'm right? And if yes, why?

 

madExcept will show exception for all app threads and I was surprised to see that without madExcept you can see exceptions for other threads only debugging from IDE.

Share this post


Link to post

All UI happens from the UI thread. So if you want an exception from another thread to result in UI, you need to marshal it into the main thread.

 

Having madExcept in your process is great. But there are a class of exceptions that you don't want to trouble the user with a bug report. I call these expected exceptions. You need to decide on a policy for those exceptions. 

Share this post


Link to post

You may try this code:

procedure GlobalExceptionHandler(ExceptionObj:TObject);
var
  LException : Exception;
begin
  if (ExceptionObj is Exception) then LException := Exception(ExceptionObj)
                                 else LException := nil;
  TExceptionHandler.ProcessException(nil,LException);
end;

constructor TExceptionHandler.Create;
begin
  inherited;
  JclStackTrackingOptions := [stStack,stRawMode,stTraceAllExceptions];
  JclStartExceptionTracking;
  Application.OnException  := ProcessException;
  ExceptionAcquired        := @GlobalExceptionHandler;
end;

destructor TExceptionHandler.Destroy;
begin
  StopExceptionHandler;
  inherited;
end;

It worked for me !

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×