Structs

Mikael Karlsson mikael.karlsson@REDACTED
Thu Jan 16 13:55:05 CET 2003


Hi Luke,
Whats wrong with:

connect(Host, User, Password) ->
    case catch connect1(Host, User, Password) of
	{ok,Result} ->
	    {ok,Result};
	{badmatch,{{error, Rsn}} ->
	    {error, otp_ftp:formaterror(Rsn)}
    end.

connect1(Host, User, Password) ->
    {ok, Pid} = otp_ftp:open(Host),
    link(Pid),
    ok = otp_ftp:user(Pid, User, Password),
    {ok, Home} = otp_ftp:pwd(Pid),
    ?event(ftp, "~p: Home is ~p", [self(), Home]),
    ok = otp_ftp:type(Pid, binary),
    {ok, {Pid, Home}}.

?/Mikael

torsdag 16 januari 2003 13:04 skrev Luke Gorrie:
>
> I still have problems in Erlang in the cases where I don't want to
> crash, i.e. the non-assertion type of error detection. Here's a
> function I wrote recently:
>
>   connect(Host, User, Password) ->
>       case otp_ftp:open(Host) of
>           {ok, Pid} ->
>               link(Pid),
>               case otp_ftp:user(Pid, User, Password) of
>                   ok ->
>                       case otp_ftp:pwd(Pid) of
>                           {ok, Home} ->
>                               ?event(ftp, "~p: Home is ~p", [self(),
> Home]), case otp_ftp:type(Pid, binary) of
>                                   ok ->
>                                       %% It is at about this level of
> nesting %% that better exception handling in %% erlang becomes appetizing..
> {ok, Pid, Home};
>                                   {error, Rsn} ->
>                                       {error, otp_ftp:formaterror(Rsn)}
>                               end;
>                           {error, Rsn} ->
>                               {error, otp_ftp:formaterror(Rsn)}
>                       end;
>                   {error, Rsn} ->
>                       {error, otp_ftp:formaterror(Rsn)}
>               end;
>           {error, Rsn} ->
>               {error, otp_ftp:formaterror(Rsn)}
>       end.
>
> Cheers,
> Luke




More information about the erlang-questions mailing list