[erlang-questions] catch

Wes James comptekki@REDACTED
Tue Mar 1 19:15:29 CET 2011


On Tue, Mar 1, 2011 at 11:01 AM, Fernando Benavides
<fernando.benavides@REDACTED> wrote:
> Just use the returned value. Try this:
> main([String]) ->
>    case length(String) of
>        0 -> io:format("~nDid you forget the number?~n~n");
>        _ ->
>            case catch(list_to_integer(String)) of
>                {'EXIT', {badarg,_}} ->
>                    io:format("~n~p~n~n",["Arg not Int"]);
>                I ->
>                    Seq=lists:seq(I+1, I+20),
>                    lists:foreach(fun(H) -> io:format("#./runcscript ~p
> ~n",[H]) end, Seq)
>            end
>    end;
> main(_) ->
>    io:format("~nDid you forget the number?~n~n").

On Tue, Mar 1, 2011 at 11:01 AM, Fernando Benavides
<fernando.benavides@REDACTED> wrote:
> Just use the returned value. Try this:
> main([String]) ->
>    case length(String) of
>        0 -> io:format("~nDid you forget the number?~n~n");
>        _ ->
>            case catch(list_to_integer(String)) of
>                {'EXIT', {badarg,_}} ->
>                    io:format("~n~p~n~n",["Arg not Int"]);
>                I ->
>                    Seq=lists:seq(I+1, I+20),
>                    lists:foreach(fun(H) -> io:format("#./runcscript ~p
> ~n",[H]) end, Seq)
>            end
>    end;
> main(_) ->
>    io:format("~nDid you forget the number?~n~n").

Thx Frenando - that makes sense :)

-wes


More information about the erlang-questions mailing list