Luke Gorrie <>
Thu Jan 16 14:01:29 CET 2003

Ulf Wiger <> wrote:
> On Thu, 16 Jan 2003, Luke Gorrie wrote:
> >I still have problems in Erlang in the cases where I don't
> >want to crash, i.e. the non-assertion type of error
> >detection. Here's a function I wrote recently:
> If the philosophy of making functions return a correct value
> or exit were followed more consistently, one only needs to
> catch exceptions at the top and format a nice message.
> The following implementation avoids the indentation misery.
> We have to wrap some functions to give them correct-or-exit
> semantics.

But the cost is that you can accidentally catch crashes inside the
otp_ftp module, right? That means you could feed arbitrary
crash-reasons into otp_ftp:formaterror. I find this a bit confusing
compared with the ugly-but-simple deeply nested code.

What I'd like is a 'try-catch' language feature that I've heard Robert
Virding talk about, where you say something like:

    try E
        Pat1 -> ..;
        PatN -> ...

And it only catches exceptions matching the patterns; others continue
uncaught. That way we could use throw({error, Reason}) and catch
{error, Reason}, and never have to worry about accidentally catching
real crashes.

I don't think that try-catch snippet is actually how he described it,
but something like that. It would make a good addition I think, since
I need 'catch' quite often, and it rarely does exactly what I want. In
particular I don't like losing the backtrace of the original error,
after I catch something that I didn't really want to.


More information about the erlang-questions mailing list