Catch exceptions when formatting log messages.