|
 |
Warp wrote:
> Darren New <dne### [at] san rr com> wrote:
>>> Also, I can't really understand how 'panic' and 'recover' are different
>>> from regular 'throw' and 'catch' in almost any other language.
>
>> Again, it's because they're not control flow statements.
>
> Hmm, I'm not sure I would call 'throw' and 'catch' control flow
> statements per se...
"throw" is a control flow statement because the compiler can tell that the
following statements don't get executed.
int xyz() { throw "Nope!"; }
The compiler should be able to suppress the warning that you're falling off
the end of the function without returning a value.
Catch is certainly a control flow statement. It even introduces a new scope,
it switches based on the class of the exception (if any) that it catches, etc.
try { do_something(); }
catch (IOException e) { alpha(); }
catch (NullPointerException e) { beta(); }
catch (MemoryException e) { gamma(); }
I'm not sure how that wouldn't count as control flow if "switch" does?
The way "catch" differs from "recover" (for example) is that there's no way
to do the equivalent of
func xyz(i int)
{
if (i < 24) recover();
}
In a language with throw and catch, there's no way to run
"do_something_that_might_panic()" without catching the value and then
rethrowing it if you don't want it.
--
Darren New, San Diego CA, USA (PST)
C# - a language whose greatest drawback
is that its best implementation comes
from a company that doesn't hate Microsoft.
Post a reply to this message
|
 |