/// <summary> /// Invokes the <see cref="IErrorFormatter.Format"/> and guards against any exceptions that it might throw. /// </summary> /// <param name="response">Response to send back</param> /// <param name="msg">Request pipeline message</param> /// <param name="exception">Caught exception</param> protected virtual void FormatException(IResponse response, ReceivedHttpRequest msg, HttpException exception) { var formatterContext = new ErrorFormatterContext(exception, msg.HttpRequest, response); try { _formatter.Format(formatterContext); } catch (Exception err) { _logger.Error(string.Format("Formatter '{0}' failed to process request.", _formatter.GetType().FullName), err); var formatter = new SimpleErrorFormatter(); formatter.Format(formatterContext); } }