[erlang-questions] erlang:raise/3 considered harmful?

Per Hedeland per@REDACTED
Sun May 15 21:17:04 CEST 2016


Lukas Larsson <garazdawi@REDACTED> wrote:
>
>Could try ... after be what you are looking for? It's not a perfect fit,
>but I thought I'd mention it as it is a construct that few people seem to
>know about.

Now we're talking:-) - indeed, try ... after is one of the solutions
I've been thinking of, the problem is that I really can't make it fit.

>>             Res = try
>>                       Fun(Data, State)
>>                   after  ->
>>                           gen_tcp:send(Sock, "done")
>>                   end,

So this ends up *always* sending the "done" after invoking the fun, but
that doesn't match the protocol - if you look at the original function,
there is one case where "continue" should be sent *instead*. I've also
considered wrapping the whole loop/3 function in try ... after, but that
instead runs into two other cases, where *nothing* should be sent:

    case gen_tcp:recv(Sock, 0) of
        {ok, "done"} ->
            {ok, State};
    ...
         Error ->
            Error

If you can come up with a way to have try ... after handle all the
cases, I'm all ears!

--Per



More information about the erlang-questions mailing list