[erlang-questions] try/catch
Wes James
comptekki@REDACTED
Mon Jun 28 23:21:45 CEST 2010
Thx. That worked. I didn't know try could return a value. I also
need to remember that an expression is more than just a single line of
code but can be several lines separated by a "," in erlang.
-wes
On Mon, Jun 28, 2010 at 3:08 PM, Allan Wegan <allanwegan@REDACTED> wrote:
<snip>
>
> Maybe, the following is what you want:
>
> do_query(Sp) ->
> {ok, Db} = pgsql:connect(?HOST, ?DB, ?USERNAME, ?PASSWORD),
> Result = try
> {_,[{_,_,Res}]} = pgsql:squery(Db, Sp),
> {Sp, Res}
> catch
> _:_ -> 'undefined';
> end,
> pgsql:terminate(Db),
> Result
> .
>
More information about the erlang-questions
mailing list