Try/Cond

Luke Gorrie luke@REDACTED
Wed Oct 22 13:27:00 CEST 2003


Joe Armstrong <joe@REDACTED> writes:

>   There is no way of getting a non-local return from a function if you
> do not use catch and throw.

And there is no way to do non-local return from a function without
buggering up the backtrace of genuine errors in Erlang today, for the
reasons Richard gave. That's why I personally avoid try/catch whenever
possible - it discards lots of good debug information for no good
reason.

That's why I think try/catch would be a Good Thing.

If we need to remove something in exchange, how about we remove the
'catch'-related programming rules. Instead of 'catch is dangerous
because foo bar baz, only use it if you're a guru", you could say "go
ahead and use try/catch if you think it will make your program
simpler".

But then we probably need a new set of programming rules for using
try/catch with higher-order functions, like a 'throw {?MODULE, ...}'
convention, since you don't know what other catch patterns will be on
the stack when your fun is called -- not to mention if your fun is
sent to another process to be executed and doesn't have your 'catch'
at all.

"Don't use 'throw' in a fun" ?

That's life, eh? :-)

-Luke




More information about the erlang-questions mailing list