码迷,mamicode.com
首页 > 其他好文 > 详细

Erlang 中处理 register 重复注册

时间:2015-01-23 22:58:38      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:

-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‘ **

Erlang 中处理 register 重复注册

标签:

原文地址:http://www.cnblogs.com/bigwhite/p/4245165.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!