Exceptions (was Re: Structs (was RE: Record selectors))

Richard Carlsson richardc@REDACTED
Thu Jan 16 18:47:39 CET 2003


On 16 Jan 2003, Luke Gorrie wrote:

>   InputStream		file = null;
> 
>   try {
>       file = new FileInputStream(...);
>       read from file;
>   } finally {
>       if (file != null)
>           file.close();
>   }


Ah! Of course - I'd forgotten about 'finally'. (Note that what "finally"
does in the case there was an exception is exactly what Shawn's code
did: catch E, execute finally-body, re-throw E.)

Interestingly, "finally" does not mix well with Erlang (and other
functional languages), mainly because of tail recursion. If an exception
occurs in the try-body, the finally-body is supposed to be executed
*after* the catch-body has its say. But the catch-body might do a tail
call, possibly never indended to return. If so: should we insert a call
to the finally-code *before* the tail call (possibly making the code
hard to understand), or should we force those calls to be non-tail
recursive, always returning to perform the cleanup code afterwards (does
not seem like a good idea either).

	/Richard


Richard Carlsson (richardc@REDACTED)   (This space intentionally left blank.)
E-mail: Richard.Carlsson@REDACTED	WWW: http://user.it.uu.se/~richardc/





More information about the erlang-questions mailing list