[erlang-questions] Inconsistent catch behaviour

Michael Radford mrad-direct-erlang@REDACTED
Thu Jun 18 17:37:50 CEST 2009


Kostis Sagonas writes:
> Ulf Wiger has already answered this question, but I want to ask a 
> different one.  Why should one bother these days with catch (even 
> mention it on this mailing list) when try-catch is available?

I sometimes find catch more succinct when I want to treat errors
and exceptions the same, more or less ignoring either one.  This
usually means 'case catch ...', like:

count () ->
  lists:foldl (fun (Node, Acc) ->
		 case catch gen_server:call({?MODULE, Node}, count) of
		   {ok, N} -> Acc + N;
		   _       -> Acc
		 end
	       end,
	       0,
	       [node() | nodes()]).

Mike


More information about the erlang-questions mailing list