RAD Studio |  |

Handling Exceptions
See Also
Collapse All
To handle exceptions in the thread function

1. Add a try...except block to the implementation of your Execute method.
2. Code the logic such as shown here:

Copy Code

    procedure TMyThreadExecute;
    begin
      try
        while not Terminated do
          PerformSomeTask;
      except
        {do something with exceptions}
      end;
    end;

Copy Code

    void __fastcall TMyThread::Execute() {
      try {
        while( !Terminated() ) {
          // perform tasks
        }
      } catch(...) { // catch specific exceptions first
        // exception—handling code
      }
    }

See Also

VCL Overview

Writing the Thread Function

Using the Main VCL Thread

Avoiding Simultaneous Thread Access to the Same Memory

Waiting for Threads

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!