Advanced TThread

The TThread class offers the programmer a collection of various properties and methods. In this section, I'll take you through the most useful ones.

The FatalException property deals with exceptions. If an exception arises inside your Execute method and is not caught, it will be handled inside the system code:

if not Thread.Terminated thentry  Thread.Execute;except  Thread.FFatalException := AcquireExceptionObject;end;

The best place to check whether this property is assigned is the OnTerminate handler. If the FatalException is not nil, we can log the exception and call ReleaseExceptionObject to destroy the exception object or we can reraise the exception. The following code from the Threads demo shows how to implement such ...

Get Mastering Delphi Programming: A Complete Reference Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.