lordsaturn
2011-03-20 17:50:53
While coding today I realized I wanted to have an exit function for all the procedures in my script, in a hierarchy.
So if my code looks like this:
What are your suggestions? I have thought about using exceptions, but that still requires making try/except blocks for every procedure/function.
TL;DR:
procedure a -> procedure b -> procedure c
I want to kill procedure a from procedure c. How?
So if my code looks like this:
procedure FindTree;
begin
if not FindColor then
begin
Writeln('FATAL ERROR, KILLING PROCEDURE STACK');
while (sender != CutDownTree) //possible inf loop... getPossibleSenders()?
sender = sender.getSender();
sender.kill();
end;
end;
procedure CutDownTree;
begin
FindTree;
FindTree;
FindTree;
FindTree;
end;
procedure TreeLoop;
begin
CutDownTree;
end;This allows me to avoid having to add a fail case for every single procedure:procedure CutDownTree;
begin
if not FindTree then
begin
Writeln('I failed - 1');
Exit;
end;
if not FindTree then
begin
Writeln('I failed - 2');
Exit;
end;
if not FindTree then Exit;
if not FindTree then Exit;
end;What are your suggestions? I have thought about using exceptions, but that still requires making try/except blocks for every procedure/function.
TL;DR:
procedure a -> procedure b -> procedure c
I want to kill procedure a from procedure c. How?