Close stream in case of exception