Handling Exceptions
Go Up to How To Build Multithreaded Applications
To handle exceptions in the thread function
- Add a try...except block to the implementation of your Execute method.
- 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
}
}