本文整理匯總了C#中System.Exception.ToErrorCode方法的典型用法代碼示例。如果您正苦於以下問題:C# Exception.ToErrorCode方法的具體用法?C# Exception.ToErrorCode怎麽用?C# Exception.ToErrorCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Exception
的用法示例。
在下文中一共展示了Exception.ToErrorCode方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: WriteJsvErrorToResponse
private static void WriteJsvErrorToResponse(this IHttpResponse response, string operationName, string errorMessage, Exception ex, int statusCode)
{
var sb = new StringBuilder();
sb.Append("{");
sb.Append("ResponseStatus:{");
sb.AppendFormat("ErrorCode:{0},", ex.ToErrorCode().EncodeJsv());
sb.AppendFormat("Message:{0},", ex.Message.EncodeJsv());
if (EndpointHost.Config.DebugMode) sb.AppendFormat("StackTrace:{0}", ex.StackTrace.EncodeJsv());
sb.Append("}");
sb.Append("}");
response.WriteErrorTextToResponse(sb, ContentType.Jsv, statusCode);
}
示例2: WriteXmlErrorToResponse
private static void WriteXmlErrorToResponse(this IHttpResponse response, string operationName, string errorMessage, Exception ex, int statusCode)
{
var sb = new StringBuilder();
sb.AppendFormat("<{0}Response xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"{1}\">\n",
operationName, EndpointHost.Config.DefaultOperationNamespace);
sb.AppendLine("<ResponseStatus>");
sb.AppendFormat("<ErrorCode>{0}</ErrorCode>\n", ex.ToErrorCode().EncodeXml());
sb.AppendFormat("<Message>{0}</Message>\n", ex.Message.EncodeXml());
if (EndpointHost.Config.DebugMode) sb.AppendFormat("<StackTrace>{0}</StackTrace>\n", ex.StackTrace.EncodeXml());
sb.AppendLine("</ResponseStatus>");
sb.AppendFormat("</{0}Response>", operationName);
response.WriteErrorTextToResponse(sb, ContentType.Xml, statusCode);
}
示例3: WriteJsonErrorToResponse
private static void WriteJsonErrorToResponse(this IHttpResponse response, string operationName, string errorMessage, Exception ex, HttpStatusCode statusCode)
{
var sb = new StringBuilder();
sb.AppendLine("{");
sb.AppendLine("\"ResponseStatus\":{");
sb.AppendFormat(" \"ErrorCode\":{0},\n", ex.ToErrorCode().EncodeJson());
sb.AppendFormat(" \"Message\":{0},\n", ex.Message.EncodeJson());
if (EndpointHost.Config.DebugMode) sb.AppendFormat(" \"StackTrace\":{0}\n", ex.StackTrace.EncodeJson());
sb.AppendLine("}");
sb.AppendLine("}");
response.WriteErrorTextToResponse(sb, ContentType.Json, statusCode);
}