<html><head><meta http-equiv="Content-Type" content="text/html charset=GB2312"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>Because you did not output the exit or error, and after block is just like finally block in Java, so it’ll always be executed. Just try modify catch block as follow:</div><div><pre style="background-color: rgb(43, 43, 43); color: rgb(169, 183, 198); font-family: Menlo; font-size: 14pt; position: static; z-index: auto;">throw:T -> io:<span style="background-color:#ffc369;">write</span>(T), io:format(<span style="color:#6a8759;">"~n"</span>);<br>exit:E -> io:<span style="background-color:#ffc369;">write</span>(E), io:format(<span style="color:#6a8759;">"~n"</span>);<br>error:Er -> io:<span style="background-color:#ffc369;">write</span>(Er), io:format(<span style="color:#6a8759;">"~n"</span>)</pre><div><br></div></div><div><div>在 2014年11月23日,15:12,全卓 <<a href="mailto:quuoms@outlook.com">quuoms@outlook.com</a>> 写道:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi,<br> I write a simple Erlang program,But it doesnot function like what i think.<br> Here is my source code.<br><br>%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<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>%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<br>I compile it and run it ,the result is:<br>%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<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>%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<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>_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>http://erlang.org/mailman/listinfo/erlang-questions<br></blockquote></div><br></body></html>