你知道在Delphi代码中捕获,记录和重新引发异常的方法吗?一个简单的例子:
procedure TForm3.Button1Click(Sender: TObject);
begin
try
raise Exception.Create('Bum');
except
on E: Exception do
begin
MyHandleException(E);
end;
end;
end;
procedure TForm3.MyHandleException(AException: Exception);
begin
ShowMessage(AException.Message);
LogThis(AException.Message);
// raise AException; - this will access violate
end;
Run Code Online (Sandbox Code Playgroud)
所以我需要在except块中重新提升它,但我想知道是否有更好的方法来编写我自己的方法来处理和(在特定条件下)重新引发异常.
我有习惯执行匿名线程,如:
TThread.CreateAnonymousThread(
procedure
begin
.....
end).start;
Run Code Online (Sandbox Code Playgroud)
但问题是如果在执行过程中会出现一些未处理的异常,那么我将不会被警告!对于我们的主线程Application.OnException.我们是否有类似的背景线程?