try .. of .. catch question

Dave Challis <>
Wed Feb 9 12:22:11 CET 2011


Hi,
I'm just learning about exceptions in Erlang, and just curious as to the 
use of try..of..catch - is it just a shortcut to combining a case with a 
try/catch?

For example, are the two blocks of code below identical? Or is there 
some subtle difference I've missed?

try
     case foo() of
         true  -> a;
         false -> b
     end
catch
     Error:Reason -> {Error, Reason}
end


try
     foo()
of
     true  -> a;
     false -> b
catch
     Error:Reason -> {Error, Reason}
end

Thanks,
-- 
Dave Challis



More information about the erlang-questions mailing list