[erlang-questions] rpc:call/4
Robert Virding
rvirding@REDACTED
Fri Feb 19 13:12:44 CET 2010
On 19 February 2010 11:09, Jayson Vantuyl <kagato@REDACTED> wrote:
> Is this true?
>
> I mean, exit / error / throw has always been a very weird division to me. I can't say that I completely understand what the breakdown is, although I usually know which one I should use. Generally, throw is used as a form of high-level flow control, exit is for when you explicitly intend to exit a process, and error is for when you have an error (which defaults to terminating the process, but can be caught if it's expected).
This is the generally accepted way of using them and I feel a good way
of indicating what you mean. Throw is for non-local returns.
About exit, which has no stacktrace, and error, which does.
Originally, there was only exit without the stacktrace and at that
time internal errors did not generate stacktraces. Then internal
errors got stacktraces (a Big Win) but exit still didn't. Then later
instead of changing exit to have stacktraces error was added. This, I
feel, was a bad choice. So now there were two different ways of
signaling a desire to exit/error with basically exactly the same
semantics.
Catch is older than try, from the time there was only exit and throw.
We decided that it would both catch both exits and non-local returns
(throw) and it would pass thrown values through unmarked and wrap an
exit value with {'EXIT',...}. It is a feature that you can fake exit
values, but as it very easy to program around this if you want to be
safe we never felt that this was a problem.
When try came along the separation into 3 different classes was
perpetuated. Unfortunately being able to catch throws, while being
very practical, I feel confused the issue of when to use what by
equating a throw with exit/error. Erlang:raise/3 adds to this
confusion because with it you can "raise" a throw which sounds strange
if you mean it be a non-local return.
> I can't imagine that the case catch is the right way to do it. The behavior is undocumented, and I really can't imagine that we should rely on it.
As the behaviour of catch is documented I assume you mean rpc here.
Robert
More information about the erlang-questions
mailing list