Log exceptions when possible

Exceptions should be logged if possible to provide more details on what happened.

Even if some code isn't supposed to be called, logging the exception is useful.