Catch

Lennart Öhman lennart.ohman@REDACTED
Tue Nov 20 16:16:05 CET 2001


Hi Fredrik and all other,

my personal experience is that the real problem is not syntactical.
(Well it is in some way since catch has two meanings...)
It is so called catch-and-throw-driven-programs. Programs where a
throw is placed very far away from its (many) matching catches.
The problem accelerates from the fact that if a lot of code is
encapsulated in a catch-and-throw, there are many potential errors
which will then by accident be caught in the catch (corresponding
to the throw).

/Lennart

Fredrik Linder wrote:
> 
> 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

-- 
-------------------------------------------------------------
Lennart Ohman                   phone   : +46-8-587 623 27
Sjoland & Thyselius Telecom AB  cellular: +46-70-552 6735
Sehlstedtsgatan 6               fax     : +46-8-667 8230
SE-115 28 STOCKHOLM, SWEDEN     email   : lennart.ohman@REDACTED



More information about the erlang-questions mailing list