unit UnitMyThread;
interface
uses
System.Classes, System.SysUtils, vcl.Forms;
type
TMyThread = class(TThread)
private
procedure DoHandleException;
procedure HandleException;
{ Private declarations }
protected
procedure Execute; override;
end;
implementation
var
FException: Exception;
procedure TMyThread.DoHandleException;
begin
// Now actually show the exception
if FException is Exception then
Application.ShowException(FException)
else
ShowException(FException, nil);
end;
procedure TMyThread.Execute;
begin
FException := nil;
try
StrToFloat('');
// raise an Exception
raise Exception.Create('I raised an exception');
except
HandleException;
end;
end;
procedure TMyThread.HandleException;
begin
// This function is virtual so you can override it
// and add your own functionality.
FException := Exception(ExceptObject);
try
// Don't show EAbort messages
if not(FException is EAbort) then
Synchronize(DoHandleException);
finally
FException := nil;
end;
end;
end.