In old times, where I had to use some resource, I declared it out of the try block, created it in the try block, and closed it in finally block. For the case if the closing will fail, it was put into inner try block.
Resource r=null;
try{
r=new Resource();
use(r);
}
catch(){
outputAndLog(something);
}
finally{
if(r != null){
try{
}
catch(){
outputAndLog(somethingElse);
}
}
}
Now we can use
try(Resource r = new Resource()){
java syntax. And the block finally becomes invisible for us. But what is in it? I mean, what happens, if the closing fails?