CloseableStream exceptions [was: Re: experience trying out lambda-8-b74]

Alan Bateman Alan.Bateman at
Mon Feb 4 11:45:51 PST 2013

On 04/02/2013 19:02, Peter Levart wrote:
> I think that every new API or feature takes some time to get used. When
> try-with-resources was introduced, nobody was thinking to use it just
> because of methods throwing checked IOException. I aggree that
> now many programmers mentally associate IOException with
> try-with-resources and you want to piggy-back on that mental perception.
> You might get quick response at the beginning, but for the price of
> long-term ugliness of exception handling when using the API. I expect
> people would be asking for another factory method throwing
> UncheckedIOException in JDK9 after the API is going to get used massively...
All methods to open or access files, directories, etc. in this API throw 
the checked IOException. It would be inconsistent to introduce a 
parallel set of methods at this point, particularly because this API 
also defines also many specific IOExceptions for cases where recovery 
might be required for specific cases.

So I think if CloseableStream is used in a try-with-resources that opens 
the file or directory then it will probably lead to usages such as:

try (...) {
} catch (UncheckedIOException e) {
     throw e.getCause();


try (...) {
} catch (IOException ioe) {
     throw new UncheckedIOException(ioe);

depending on whether you want to propagate a checked or unchecked 
exception. One of two examples in the javadoc might help.


More information about the lambda-dev mailing list