Catch IOException for closing