Try to close the file even if an exception occurred