What's differenct between 'catch 1=0' and '(catch 1=0)'?
Erlang R14B03 (erts-5.8.4) [source] [64-bit] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.8.4 (abort with ^G)
1> 1=0.
开发者_JAVA百科** exception error: no match of right hand side value 0
2> catch 1=0.
{'EXIT',{{badmatch,0},[{erl_eval,expr,3}]}}
3> (catch 1=0).
{'EXIT',{{badmatch,0},[{erl_eval,expr,3}]}}
There is no difference. The only thing that changes is when you try to bind the result of the operation to a variable:
1> X = catch 1/0.
* 1: syntax error before: 'catch'
1> X = (catch 1/0).
{'EXIT',{badarith,[{erlang,'/',[1,0]},
{erl_eval,do_apply,5},
{erl_eval,expr,5},
{erl_eval,expr,5},
{shell,exprs,7},
{shell,eval_exprs,7},
{shell,eval_loop,3}]}}
That's simply a question of precedence between catch
as a prefix operator, and =
as an infix operator. The parentheses help make the use case unambiguous in priority.
Otherwise, they're exactly the same.
精彩评论