trycatch.erl

trycatch.erl — Erlang source code, 588 bytes

Continguts del fitxer

-module(trycatch).
-compile(export_all).

provocar_error(1) ->
    a;
provocar_error(2) ->
    throw(a);
provocar_error(3) ->
    exit(a);
provocar_error(4) ->
    {'EXIT', a};
provocar_error(5) ->
    erlang:error(a).


prova() -> [capturar(I) || I <- [1,2,3,4,5]].

capturar(N) ->
    try provocar_error(N) of
        Val -> {N, noCapturat, Val}
    catch
        throw:X -> {N, capturat, throw, X};
        exit:X -> {N, capturat, exit, X};
        error:X -> {N, capturat, error, X}
    end.

prova2() -> [{I, (catch provocar_error(I))} || I <- [1,2,3,4,5]].