RAD Studio
ContentsIndex
PreviousUpNext
Handling Exceptions
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:

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

 

void __fastcall TMyThread::Execute() {
  try {
    while( !Terminated() ) {
      // perform tasks
    }
  } catch(...) { // catch specific exceptions first
    // exception—handling code
  }
}  
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!