Please correct me if this is wrong: In Java 7's try-with-resources statement, any exceptions thrown by the resource's close()
method must be either declared as thrown by my method or I must wrap the whole try in another try
which catches any exceptions thrown by close()
.
If so, I have to wonder if I will make much use of it. I certainly don't want to throw
the exceptions thrown by close()
, the caller won't know what to do with that. And a try
wrapping another try
just to handle close()
would not look very elegant, to me at least.
EDIT: I think I accidentally asked two questions, one of which was a duplicate.
Question 1. Do I have to declare that my method throws the exception from the close()
method or wrap the try-with-resources in another try? (Not answered in proposed duplicate.)
Question 2. Is there a way to close the resource silently? (Clearly a duplicate, so I am taking that sentence out of the question. Hopefully this makes the question satisfactorily unique.)