Re: Closing Files that Weren't Successfully Opened
Michal Kleczek wrote:
Lew wrote:
Michal Kleczek wrote:
Lew wrote:
Michal Kleczek wrote:
A file handle. You do not call close() on FileReader in case
BufferedReader constructor throws.
Non-issue. If FileReader doesn't then BufferedReader won't.
1. It can always throw a RuntimeException or an Error. Depending on
situation it should or should not be handled gracefully hence it _can_ be an
issue. If it is a library (reusable) code it certainly is.
If it throws an Error your resources are released because the program crashes.
Same for RuntimeException.
2. My original reply to Robert's post was:
<quote>
That only works because both InputStreamReader and BufferedReader
constructors don't throw.
But it is not safe to do the same for:
final ObjectInputStream ois =
new ObjectInputStream(new FileInputStream("foo.txt"));
</quote>
You've read it before replying, haven't you?
and you were mistaken then, too.
--
Lew
Honi soit qui mal y pense.