Don't assume particular attributes on the exception object.
Ensure var is initialized.
Improve logging.