假设我有三个(或更多)过程,其中一些相互调用,如下所示,任何一个都可能失败。如果它们中的任何一个失败,我希望“主”程序立即记录失败并终止程序。在Delphi中,“传回”异常到每个前置过程调用的正确语法是什么?如果有人能帮助我让主程序的Try/except块识别哪一部分失败,那就更好了!以下是三个过程和主程序的示例伪代码。 (我认为我理解原则,与“引发”有关,但需要一些关于实际语法和应该使用哪些代码的帮助)
//////////////////////////////////////
Procedure DoProcA
begin
try
begin
{stuff}; //stuff that might fall
end;
except
on E : Exception do
begin
LogError ('error in A');
end //on E
end;//try
//////////////////////////////////////
Procedure DoProcB
begin
try
begin
Do ProcC; //another proc that might fail
{other stuff}
end;
except
on E : Exception do
begin
LogError ('error in B');
end //on E
end;//try
//////////////////////////////////////
Procedure DoProcC
begin
try
begin
{Do stuff} //even more stuf fthat might fail
end;
except
on E : Exception do
begin
LogError ('error in C');
end //on E
end;//try
//////////////////////////////////////
//Main programo
begin
try
DoProcA;
DoProcB;
{other stuff}
except
{here I want to be able to do something like
if failure of A, B or C then
begin
LogError ('Failure somewhere in A, B or C');
application.terminate;
end;}
end; //try
end.