Erlang 中处理 register 重复注册

-module(demo).
-compile(export_all).

foo() ->
    receive
    after 100000 ->
        io:format("ok~n")
    end.

main() ->    
    register(name1, spawn(fun() -> foo() end)),
    case (catch register(name1, spawn(fun() -> foo() end))) of
        true -> true;        
        _ -> io:format("error~n")
    end.


使用 catch 处理。因为是运行时错误。

注意 catch 被小括号括起,如若不然,会出错,出错原因为: ** 1: syntax error before: 'catch' **

posted @ 2015-01-23 22:26  bigwhite  阅读(291)  评论(0编辑  收藏  举报