参考URL:
http://erlangworld.web.fc2.com/sequential_programming/error_handling.html
ソース:
-module(try_test).
-compile(export_all).
demo1() ->
[catcher(I) || I <- [1,2]].
catcher(N) ->
try generate_exception(N) of
Val -> {N, normal, Val}
catch
throw:X -> {N, caught, thrown, X}
end.
generate_exception(1) -> a;
generate_exception(2) -> throw(b).
実行結果:
3> c(try_test).
{ok,try_test}
4> try_test:demo1().
[{1,normal,a},{2,caught,thrown,b}]
5>
0 件のコメント:
コメントを投稿