<div dir="ltr">Hi!<div><br></div><div>What would you expect the code would do?</div><div><br></div><div>Try replacing lists:foreach with lists:map and notice that the result is [a, throw_exception, error_exception, exit_exception, {'EXIT',a}]. Maybe this is what you wanted? </div><div><br></div><div>best regards,</div><div>Vlad</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Nov 23, 2014 at 8:12 AM, 全卓 <span dir="ltr"><<a href="mailto:quuoms@outlook.com" target="_blank">quuoms@outlook.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
    I write a simple Erlang program,But it doesnot function like what i think.<br>
    Here is my source code.<br>
<br>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<u></u>%%%%%%%%%%%<br>
-module(exception).<br>
-export([start/0]).<br>
<br>
generate_exception(1) -><br>
    a;<br>
generate_exception(2) -><br>
    throw(throw_exception);<br>
generate_exception(3) -><br>
    error(error_exception);<br>
generate_exception(4) -><br>
    exit(exit_exception);<br>
generate_exception(5) -><br>
    {'EXIT',a}.<br>
<br>
start() -><br>
    lists:foreach(fun (I) -> try generate_exception(I) of<br>
                 Res -> Res<br>
                 catch<br>
                 throw:T -> T;<br>
                 exit:E -> E;<br>
                 error: Er -> Er<br>
                 after<br>
                 io:format("exec this line:~p~n",[I])<br>
                 end<br>
          end,lists:seq(1,5)).<br>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<u></u>%%%%%%%%<br>
I compile it and run it ,the result is:<br>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<u></u>%%%%%%%%<br>
exec this line:1<br>
exec this line:2<br>
exec this line:3<br>
exec this line:4<br>
exec this line:5<br>
ok<br>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<u></u>%%%%%%%%<br>
<br>
It seems that no exception has been caught, why?Or,I have something wrong?<br>
By the way,My Otp version is: Erlang/OTP 17,Install from source code,<br>
OS is Ubuntu 14.04.<br>
<br>
Thank you !<br>
______________________________<u></u>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<u></u>listinfo/erlang-questions</a><br>
</blockquote></div><br></div>