[erlang-questions] catch
Fernando Benavides
fernando.benavides@REDACTED
Tue Mar 1 19:01:16 CET 2011
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 2:46 PM, Wes James <comptekki@REDACTED> wrote:
> I have this escript to create a list of output:
>
> 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=list_to_integer(String),
> 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").
>
>
> I first tried:
>
> case catch(I=list_to_integer(String)) of
>
> But I think there was an error that I was unsafe.
>
> Is there a way to do a variable assignment to retain a good value so
> you don't have to do the catch then redo it when it is valid? I.e.,
> list_to_ineger will be run twice if it is a valid integer. Is there a
> way to do this once?
>
> thx,
>
> -wes
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>
--
*Fernando Benavides <http://google.com/profiles/greenmellon>*
More information about the erlang-questions
mailing list