3 ms·
> throw is not at all like GOTO They are the same thing. To see it clearly, replace each exception with a label, each "try" by a no-op, each "catch" by a labe
by carapace 6y ago
> throw is not at all like GOTO
They are the same thing.
To see it clearly, replace each exception with a label, each "try" by a
no-op, each "catch" by a label statement, and each "throw" by a GOTO
statement.
try:
foo()
catch BarException
baz()
def foo():
...
throw BarException
...
Is like:
CALL foo
GOTO end
LABEL bar
CALL baz
LABEL end
LABEL foo
...
GOTO bar
...
RET
Either you have relatively simple exceptions and the equivalent GOTOs
would also be simple enough to be not "considered harmful"; -or- you have
complicated exceptions, which is really an ad hoc state machine, and you
might be better off making that explicit rather than hiding it in a
tangle of try/catch/throw control-flow logic, eh?