[erlang-questions] Old school exceptions vs. new age one

Richard Carlsson <>
Mon Apr 28 18:04:16 CEST 2008


Thomas Lindgren wrote:
> Another part of the effort to turn Erlang into ML, eh?
> :-)

On the contrary - the exception handling in ML lacks the
success-case branch that you get in Erlang with try...of...
(hence, it is ML that needs to be turned into Erlang). :-)

> I have to note that I nearly always use 'catch' rather
> than 'try', and even consider 'catch' taking care of
> all cases in a great big mess the usually desired
> behaviour.

It does handle the "I just want to catch everything" case
pretty well, and that was one of the main things we had to
work out when designing the try-construct: there shouldn't
be cases that 'catch' did more efficiently/compactly than
'try'. (In some cases the equivalent 'try' is a bit more
verbose, but it's just a matter of a few more characters to
type - it's not a completely different control flow.)

> But since I so clearly Don't Get It, I'm
> wondering: what properties of 'try' do people consider
> great _in practice_? What has saved your bacon in
> switching from old to new school?

Personally, I've 1) benefited from being able to
catch only some particular exceptions and letting all
the rest be re-thrown, passing them through unchanged
(this is just not possible with 'catch'), and 2) used
'after' quite a lot - e.g. the core of EUnit relies
very much on being able to do 'after'-stuff regardless
of how the test terminated and without modifying the
information in exceptions that pass through.

And splitting the clauses into 'of...' and 'catch...'
sections makes for more readable code, so the syntax is
nicer, in my (totally objective) opinion. ;-)

     /Richard





More information about the erlang-questions mailing list