Catch

Fredrik Linder fredrik.linder@REDACTED
Tue Nov 20 20:53:22 CET 2001


Hi all

I forgot to mension why this proposal came up in the first place! In
core-erlang do they have a try-statement, and hence would it be attractive
to have it also in erlang, so that the compiler would not have to catch
everything everytime, but only those exceptions that are explicitly matched.
It was my impression that this could slightly speed up the compiled code, or
at least simplify translation between erlang and core-erlang.

To be able to do so must erlang define a way to differentiate between normal
excecution code and exception execution code, and this is not possible in
current erlang.

With the given proposal could differentiation between normal execution code
and exception execution code be made without having to introduce a new
statement.

An [erlang:]throw/0 could also be introduced to re-throw the current
exception, when caught.

The last part would also unify the syntax between recieve and case
statements. Is it totally wrong to see signals as exceptions between
processes?

/Fredrik

----- Original Message -----
From: "Fredrik Linder" <qtxfklr@REDACTED>
To: <erlang-questions@REDACTED>
Sent: Tuesday, November 20, 2001 3:44 PM
Subject: Catch


> Hi
>
> At the Erlang Workshop in Florence did a discussion about separating
> code for normal execution from code for exception(al?) execution take
> place.
>
> Now I am wondering what the Erlang community think about a proposal that
> came up.
>
> The proposal is to extend where a catch might be placed. Note that the
> current use of catches could still be valid.
>
> Proposal:
>
> case <expr> of
>     NormalMatch1 ->
>         blabla;
>     NormalMatch2 ->
>         blabla
> catch
>     {'EXIT', Reason} ->
>         blabla;
>     ExceptionMatch2 ->
>         blabla
> end
>
> If this feels like a good way of doing it, then maybe also extend this
> to receive statements:
>
> receive
>     NormalMatch ->
>         blabla
> after
>     Time ->
>         blabla
> catch
>     {'EXIT', Pid, Reason} ->
>         blabla;
>     SignalMatch ->
>         blabla
> end
>
> By introducing an 'EXIT' record could this be extended further:
>
> -record('EXIT', {pid, reason}).
>
> recieve|case <expr> of
>     NormalMatch ->
>         blabla
> catch
>     #'EXIT'{} ->
>         blabla;
>     #'EXIT'{pid = Pid} ->    % In a case statement is Pid == self()
>         blabla;
>     #'EXIT'{reason = Reason} ->
>         blabla
> end
>
> The last suggestion could be implemented as syntactical suger (I guess).
>
> /Fredrik
>




More information about the erlang-questions mailing list