catch gen_udp:open

Vance Shipley <>
Wed Nov 27 17:35:21 CET 2002


After perusing the megaco source I am left with two questions in
regards to the use of catch with gen_tcp and gen_udp.  I see that 
in megaco_udp.erl the call to gen_udp:open/2 is wrapped in a catch
however I don't see that the catch return is caught at all.

Is this a mistake? 

In megaco_tcp.erl the call to gen_tcp:connect/3 is wrapped in a catch
but here I see what I would expect; the case matches {'EXIT', _Reason}.

So now my second question is do I need to worry about this?  Is this
just paranoia or should I be doing the same thing?  Why would it exit?

	-Vance

(R9B-0)

megaco_udp.erl
--------------

       case catch gen_udp:open(UdpRec#megaco_udp.port, IpOpts) of
           {ok, Socket} ->
               ?udp_debug(UdpRec, "udp open", []),
               NewUdpRec = UdpRec#megaco_udp{socket = Socket},
               case start_udp_server(SupPid, NewUdpRec) of
                   {ok, ControlPid} ->
                       gen_udp:controlling_process(Socket, ControlPid),
                       {ok, Socket, ControlPid};
                   {error, Reason} ->
                       Error = {error, {could_not_start_udp_server, Reason}},
                       ?udp_debug({socket, Socket}, "udp close", []),
                       gen_udp:close(Socket),
                       Error

               end;
           {error, Reason} ->
               Error = {error, {could_not_open_udp_port, Reason}},
               ?udp_debug(UdpRec, "udp open failed", [Error]),
               Error
       end;


megaco_tcp.erl
--------------

       case catch gen_tcp:connect(TcpRec#megaco_tcp.host,
                                  TcpRec#megaco_tcp.port,
                                  IpOpt) of
           {ok, Socket} ->
               %%----------------------------------------------
               %% Socket up start a new control process
               case start_connection(SupPid,
                                     TcpRec#megaco_tcp{socket = Socket})
                   of
                   {ok, Pid} ->
                       gen_tcp:controlling_process(Socket, Pid),
                       {ok, Socket, Pid};
                   {error, Reason} ->
                       {error, Reason}
               end;
           {error, Reason} ->
               Error = {error, {gen_tcp_connect, Reason}},
               ?tcp_debug(TcpRec, "tcp connect failed", [Error]),
               Error;
           {'EXIT', _Reason} = Exit ->
               Error = {error, {gen_tcp_connect, Exit}},
               ?tcp_debug(TcpRec, "tcp connect failed", [Error]),
               Error
       end;




More information about the erlang-questions mailing list