catch gen_udp:open
Hakan Mattsson
hakan@REDACTED
Thu Nov 28 11:18:20 CET 2002
On Wed, 27 Nov 2002, Vance Shipley wrote:
Vance> After perusing the megaco source I am left with two questions in
Vance> regards to the use of catch with gen_tcp and gen_udp. I see that
Vance> in megaco_udp.erl the call to gen_udp:open/2 is wrapped in a catch
Vance> however I don't see that the catch return is caught at all.
Vance>
Vance> Is this a mistake?
Yes, this is a bug.
Vance> In megaco_tcp.erl the call to gen_tcp:connect/3 is wrapped in a catch
Vance> but here I see what I would expect; the case matches {'EXIT', _Reason}.
Vance>
Vance> So now my second question is do I need to worry about this? Is this
Vance> just paranoia or should I be doing the same thing? Why would it exit?
Despite the kernel documentation, I think that bad options to gen_tcp
and gen_udp are intended to cause an exit. At least this is the
behaviour for gen_udp:open/2, while a bad option to gen_tcp:connect/3
returns an {'EXIT', Reason} tuple:
% erl
Erlang (BEAM) emulator version 2002.10.08 [source]
Eshell V2002.10.08 (abort with ^G)
1> gen_udp:open(8888, [bad]).
** exited: badarg **
2> gen_tcp:connect("baidarka", 8888, [bad]).
{'EXIT',badarg}
3> gen_tcp:connect("baidarka", 8888, really_bad).
{'EXIT',{badarg,[{lists,keysearch,[tcp_module,1,really_bad]},
{gen_tcp,mod,1},
{gen_tcp,connect1,4},
{gen_tcp,connect,4},
{erl_eval,expr,3},
{erl_eval,exprs,4},
{shell,eval_loop,2}]}}
Both megaco_tcp and megaco_udp allows the user to add arbitrary
gen_tcp/gen_udp options to the ones that megaco defaults to and we
wanted to handle all error cases uniformly. If you have a more static
usage of gen_tcp/gen_udp options you would not need to catch the
function calls.
/Håkan
More information about the erlang-questions
mailing list