Small poll

Pascal Brisset pascal.brisset-ml@REDACTED
Wed Dec 17 21:17:35 CET 2003


Chris Pressey writes:
 >   foo(Bar) ->
 >     ok = file:setcwd(moo(Bar)),
 >     {ok, File} = file:open(zoo(Bar)),
 >     {ok, Records} = read_records(File),
 >     ok = file:close(File),
 >     Records.
 > 
 > So, the intent of the function is clearly to fail outright with
 > 'badmatch' if anything goes wrong.  foo/1's callers presumably wrap
 > their calls to foo (or their calls to whatever eventually calls foo) in
 > a catch. [...]

Note that if foo/1's caller catches failures from read_records/1,
file descriptors will be leaked.  Days later, the beam process runs
out of descriptors and strange things happen.  Been there.

What would seasoned Erlangers recommend to avoid this ?

-- Pascal




More information about the erlang-questions mailing list