我正在编写 IPC 应用程序。我想从进程 B 静默捕获异常,然后将异常详细信息作为字符串发送到进程 A。我能够从主线程捕获异常,但在从不同线程捕获异常时遇到问题。
procedure TForm1.ApplicationEvents1Exception(Sender: TObject; E: Exception);
begin
SendExceptionToAnotherProcess(E.ToString);
end;
type
AThread = class(TThread)
protected
procedure Execute; override;
end;
procedure AThread.Execute; // Main thread cannot catch such runtime exception
var uq1, uq2: UInt64;
s1: Single;
d1: Double;
begin
uq1 := $9000000000000000;
s1 := uq1; // no problem here
// exception class $C0000090 with message 'c0000090 FLOAT_INVALID_OPERATION'.
uq2 := round(s1); // but back-conversion crashes
end;
procedure TForm1.Button1Click(Sender: TObject);
var
T: AThread;
begin
T := AThread.Create(True);
T.Start;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
raise Exception.Create('I can catch it');
end;
有没有办法从所有线程中捕获异常?异常可能由不同线程中的第三个库或 ActiveX 控件引发。