There are two possibilities that I can think of:
- It's an oversight
- Both calls to
close()
can throw an exception. If the first one throws an exception, the second one would be skipped - unless of course the first one was wrapped in its owntry
/catch
block. The second one doesn't need atry
/catch
block since if it fails, there is no subsequent code that will be skipped
In the "real world", I would say that the answer is #1. The reason I would think #2 to be unlikely is that there is usually some other code that you will want to execute, even if you can't close some stream. This would be especially true had the catch
blocks not caught an exception (or re-threw a different exception) since a fresh exception in the finally
block would replace the original exception and you would never know that it had happened.
Update
As another answer has pointed out, PrintWriter.close()
does not in fact throw an IOException
, even though the parent interface Writer
does declare that close()
can throw an IOException
. So that may be a better explanation.