handle null connection in error handling