[erlang-questions] Exceptions vs Tagged Values

Ulf Wiger ulf@REDACTED
Tue Nov 14 21:58:10 CET 2006

Den 2006-11-14 20:19:33 skrev Richard A. O'Keefe <ok@REDACTED>:

> (*) for file:open/2 in particular, i see no reason for it to do
> 	anything but throw or return the fd.  if the file should be
> 	there, that's what you want; if you don't know if the file
> 	exists/is readable, you should call read_file_info/1 first.
> The fact that read_file_info/1 succeeds and says the file is accessible
> does NOT guarantee that you will be able to open the file.
> Some possible reasons:
> [...]
> I have faced this problem in C and in implementing I/O support for  
> Prolog.
> The *only* way to be sure that opening a file will work is to try to open
> the file.  Nothing else tells you *exactly* what you need to know.

But in most cases, read_file_info() does tell you whether
or not you can expect file:open() to work, given that some
exceptional condition (e.g. out of file descriptors) does
not happen, and that there isn't a race condition for the
file (which could also be regarded as exceptional.

In these cases, I'd be willing to live with read_file_info()
telling me that I should be able to expect it to work, and
then file:open() throwing an exception if it still doesn't.

Ulf W
Ulf Wiger

More information about the erlang-questions mailing list