Raise Exception in thread

delphi package - automated exception handling

Raise Exception in thread

Postby dredfil » Thu Oct 24, 2019 7:09 pm

In my project there are many objects of class TThread. Each of them has own log, that can be viewed in mainform.
Some of threads crash and madExcept processed exception, How i can also write exception message to log after MadExcept catch?

Code: Select all
procedure TMainForm.ThrOnTerm(Sender: TObject);
  i: word;
  E: Exception;
  if not TBotThread(Sender).DeleteBotData then begin
    E:=(Bot[i].thr.FatalException as Exception);
    if E<>nil then
      Bot[i].thr.log('Ошибка: '+E.ClassName+' '+E.Message,2);   ----- i write log here, but nothing catch


Posts: 1
Joined: Thu Oct 24, 2019 7:00 pm

Re: Raise Exception in thread

Postby madshi » Thu Oct 31, 2019 4:34 pm

Do you need access to thread-specific variables/resources, when writing to the log? One easy solution would be to use "RegisterExceptionHandler" and in your registered handler then write something to the log. However, the handler will not be called in the context of the crashing thread, so this may not be what you want? Alternatively, you could add a try..except block around each thread's Execute method and in the try..except block write something to the log, then do "raise" to re-raise the exception, so madExcept becomes active. Or alternatively, instead of using "raise" you could also directly call madExcept.HandleException().
Site Admin
Posts: 10268
Joined: Sun Mar 21, 2004 5:25 pm

Return to madExcept

Who is online

Users browsing this forum: No registered users and 11 guests