[erlang-questions] Exceptions vs Tagged Values

Chandru chandrashekhar.mullaparthi@REDACTED
Wed Nov 15 11:16:22 CET 2006


Quite frequently, I resort to returning tagged tuples as well because I want
to print nice error messages to logs for the Support team to look at. They
can't understand crash reports and I don't blame them for it.

What would be nice though is for the programmer to be able to specify what
additional information should be included in an exception should a match
expression fail. At the moment, we get a badmatch exception which is not
very useful when you want to report exactly what went wrong. Here is some
pseudo code to illustrate my point.

foo() ->
   try
     do_something()
   catch
     exit:{{badmatch, {error, enoent}}, opening_file1_failed} ->
           ok;
     exit:{{badmatch, {error, enofile}}, opening_file2_failed} ->
           ok;
     exit:Reason ->
           {'EXIT', Reason}
   end.

do_something() ->
    {ok, Iod1}:{exception, opening_file1_failed} = file:open("file1.txt",
[read, raw]),
    {ok, Iod2}:{exception, opening_file2_failed} = file:open("file2.txt",
[write, raw]),
    bar(Iod1, Iod2).


cheers
Chandru
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20061115/92572160/attachment.htm>


More information about the erlang-questions mailing list