我還有一個問題!請看看下面這個例子:如何在Delphi中將異常從一個線程傳遞到另一個線程(調用者的線程)?
// There is a class with some method:
type
TMyClass = class
public
procedure Proc1;
end;
// There is a some thread class:
TMyThread = class(TThread)
protected
procedure Execute; override;
end;
procedure TMyClass.Proc1;
begin
// this method is just calling another thread:
with TMyThread.Create(True) do
begin
FreeOnTerminate := True;
Resume;
end;
// + there are some more actions
end;
procedure TMyThread.Execute;
begin
// in this example this thread just throws exception:
raise Exception.Create('Some exception');
end;
所有我想要的東西 - 就是要引發的異常在TMyClass.Proc1並把它像這樣:
var
myObject: TMyClass;
begin
myObject := TMyClass.Create;
try
myObject.Proc1; // launch and watch what happenings
except
on E: Exception do
WriteErrorLog(E.Message);
end;
FreeAndNil(myObject);
end;
請告訴我,我該怎麼做的東西喜歡這個? 非常感謝!
哦!還有一件事 - 即時編碼在德爾福5,所以我沒有「FatalException」TThread的屬性或有關..
您需要接受一個答案,或者如果沒有足夠完整的答案,您可以指示例如通過評論 – Remko 2010-09-29 11:27:08