idiom for clearing up resources?

WILLIAMS Dominic D.WILLIAMS@REDACTED
Mon Aug 25 13:52:33 CEST 2003


Hello,

Is there an idiom for initializing and clearing up resources
(e.g. files) needed by an Erlang function, in such a way that the
clear-up code gets called even in the face of an error?

e.g.

myfunc() ->
	ok = file:make_dir("c:/tmp/foo"),
	% do some stuff
	ok = file:del_dir("c:/tmp/foo").

I want the last line to be called even if "do some stuff" crashes.
Basically, coming from a C++ background, this is the code I would
have put in something's destructor, and I am wondering what Erlangers
do...

Cheers,

Dominic.



More information about the erlang-questions mailing list