Improve handling of unexpected exceptions.