Log an exception if an unexpected error occurs.