Arno Garrels wrote:
> When I caught an exception in methode Execute and re-raise it
> in a synchronised TThreadMethode, the RTL tries to free the 
> Exception-Objekt twice. Does anybody have some tip what's wrong
> with my code? Thanks in advance.

What Delphi version are you using? I'm pretty sure that as of Delphi 6, 
TThread already catches exceptions in Execute and raises them synchronized.

> procedure TWorkerThread.Execute;
> [..]
>   if Assigned(FJobObj) and (not Terminated) then
>   begin
>     FJobObj.FThread := Self;
>     try
>       try
>         FJobObj.Execute;
>         raise Exception.Create('TestTest');
>       except
>         on E: Exception do
>         begin
>           if Assigned(FJobObj) and (not Terminated) then
>           begin
>             FJobObj.FLastException := E;

There's a function you can call here that tells the RTL not to free the 
exception object. I think it's named AcquireException.

There's another function named ReleaseException that you're supposed to 
call when you're finished with the exception (in the main thread, in 
your case). I'm not sure whether it really does anything, though.

>             SyncResult;
>           end;
>         end;
>       end;
>     finally
>       { Following conditions return false, }
>       { and Execute is exited (FreeOnTerminate = TRUE)   }
>       if Assigned(FJobObj) and (not Terminated) then
>         SyncResult;
>       if Terminated then
>         FreeAndNil(FJobObj);
>     end;
>   end;
> [..]

-- 
Rob
_______________________________________________
Delphi mailing list -> [email protected]
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

Reply via email to