本文整理汇总了C#中System.Exception.GetMessage方法的典型用法代码示例。如果您正苦于以下问题:C# Exception.GetMessage方法的具体用法?C# Exception.GetMessage怎么用?C# Exception.GetMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Exception
的用法示例。
在下文中一共展示了Exception.GetMessage方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetExceptionHeaders
public static void SetExceptionHeaders(Dictionary<string, string> headers, Exception e)
{
headers["NServiceBus.ExceptionInfo.ExceptionType"] = e.GetType().FullName;
if (e.InnerException != null)
{
headers["NServiceBus.ExceptionInfo.InnerExceptionType"] = e.InnerException.GetType().FullName;
}
headers["NServiceBus.ExceptionInfo.HelpLink"] = e.HelpLink;
headers["NServiceBus.ExceptionInfo.Message"] = e.GetMessage().Truncate(16384);
headers["NServiceBus.ExceptionInfo.Source"] = e.Source;
headers["NServiceBus.ExceptionInfo.StackTrace"] = e.ToString();
headers["NServiceBus.TimeOfFailure"] = DateTimeExtensions.ToWireFormattedString(DateTime.UtcNow);
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (e.Data == null)
// ReSharper disable HeuristicUnreachableCode
{
return;
}
// ReSharper restore HeuristicUnreachableCode
foreach (DictionaryEntry entry in e.Data)
{
if (entry.Value == null)
{
continue;
}
headers["NServiceBus.ExceptionInfo.Data." + entry.Key] = entry.Value.ToString();
}
}
示例2: OnError
public static void OnError(Exception e)
{
if (e == null || e is ThreadAbortException) return;
var msg = e.GetMessage();
File.WriteAllText("crash.log", msg);
MessageBox.Show(
"Something really TERRIBLE happened! Here are the details: (you can see it later in crash.log)" +
Environment.NewLine + msg, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
}
示例3: ToErrorModelInternal
private static Error ToErrorModelInternal(Exception exception, ExceptionlessClient client, bool isInner = false) {
var log = client.Configuration.Resolver.GetLog();
Type type = exception.GetType();
var error = new Error {
Message = exception.GetMessage(),
Type = type.FullName
};
if (!isInner)
error.Modules = GetLoadedModules(log);
error.PopulateStackTrace(error, exception, log);
try {
PropertyInfo info = type.GetProperty("HResult", BindingFlags.NonPublic | BindingFlags.Instance);
if (info != null)
error.Code = info.GetValue(exception, null).ToString();
} catch (Exception) { }
try {
if (exception.TargetSite != null) {
error.TargetMethod = new Method();
error.TargetMethod.PopulateMethod(error, exception.TargetSite);
}
} catch (Exception ex) {
log.Error(typeof(ExceptionlessClient), ex, "Error populating TargetMethod: " + ex.Message);
}
try {
var exclusions = _exceptionExclusions.Union(client.Configuration.DataExclusions);
var extraProperties = type.GetPublicProperties().Where(p => !p.Name.AnyWildcardMatches(exclusions, true)).ToDictionary(p => p.Name, p => {
try {
return p.GetValue(exception, null);
} catch { }
return null;
});
extraProperties = extraProperties.Where(kvp => !ValueIsEmpty(kvp.Value)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
if (extraProperties.Count > 0 && !error.Data.ContainsKey(Error.KnownDataKeys.ExtraProperties)) {
error.AddObject(new ExtendedDataInfo {
Data = extraProperties,
Name = Error.KnownDataKeys.ExtraProperties,
IgnoreSerializationErrors = true,
MaxDepthToSerialize = 5
}, client);
}
} catch { }
if (exception.InnerException != null)
error.Inner = ToErrorModelInternal(exception.InnerException, client, true);
return error;
}
示例4: SetExceptionHeaders
public static void SetExceptionHeaders(this TransportMessage message,Exception e, Address failedQueue, string reason = null)
{
if (!string.IsNullOrWhiteSpace(reason))
{
message.Headers["NServiceBus.ExceptionInfo.Reason"] = reason;
}
message.Headers["NServiceBus.ExceptionInfo.ExceptionType"] = e.GetType().FullName;
if (e.InnerException != null)
{
message.Headers["NServiceBus.ExceptionInfo.InnerExceptionType"] = e.InnerException.GetType().FullName;
}
message.Headers["NServiceBus.ExceptionInfo.HelpLink"] = e.HelpLink;
message.Headers["NServiceBus.ExceptionInfo.Message"] = e.GetMessage();
message.Headers["NServiceBus.ExceptionInfo.Source"] = e.Source;
message.Headers["NServiceBus.ExceptionInfo.StackTrace"] = e.StackTrace;
message.Headers[FaultsHeaderKeys.FailedQ] = failedQueue.ToString();
message.Headers["NServiceBus.TimeOfFailure"] = DateTimeExtensions.ToWireFormattedString(DateTime.UtcNow);
}
示例5: SetFailureHeaders
public static void SetFailureHeaders(this TransportMessage message, Exception e, string reason = null)
{
if (!string.IsNullOrWhiteSpace(reason))
{
message.Headers[HeaderKeys.ExceptionReason] = reason;
}
message.Headers[HeaderKeys.ExceptionType] = e.GetType().FullName;
if (e.InnerException != null)
{
message.Headers[HeaderKeys.InnerExceptionType] = e.InnerException.GetType().FullName;
}
message.Headers[HeaderKeys.ExceptionHelpLink] = e.HelpLink;
message.Headers[HeaderKeys.ExceptionMessage] = e.GetMessage();
message.Headers[HeaderKeys.ExceptionSource] = e.Source;
message.Headers[HeaderKeys.ExceptionStacktrace] = e.StackTrace;
message.Headers[HeaderKeys.TimeOfFailure] = DateTimeOffset.UtcNow.ToWireFormattedString();
}
示例6: SetExceptionHeaders
internal static void SetExceptionHeaders(Dictionary<string, string> headers, Exception e, Address failedQueue, string reason, bool legacyStackTrace)
{
if (!string.IsNullOrWhiteSpace(reason))
{
headers["NServiceBus.ExceptionInfo.Reason"] = reason;
}
headers["NServiceBus.ExceptionInfo.ExceptionType"] = e.GetType().FullName;
if (e.InnerException != null)
{
headers["NServiceBus.ExceptionInfo.InnerExceptionType"] = e.InnerException.GetType().FullName;
}
headers["NServiceBus.ExceptionInfo.HelpLink"] = e.HelpLink;
headers["NServiceBus.ExceptionInfo.Message"] = e.GetMessage();
headers["NServiceBus.ExceptionInfo.Source"] = e.Source;
if (legacyStackTrace)
{
headers["NServiceBus.ExceptionInfo.StackTrace"] = e.StackTrace;
}
else
{
headers["NServiceBus.ExceptionInfo.StackTrace"] = e.ToString();
}
headers[FaultsHeaderKeys.FailedQ] = failedQueue.ToString();
headers["NServiceBus.TimeOfFailure"] = DateTimeExtensions.ToWireFormattedString(DateTime.UtcNow);
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if(e.Data == null)
// ReSharper disable once HeuristicUnreachableCode
return;
foreach (DictionaryEntry entry in e.Data)
{
if (entry.Value == null)
continue;
headers["NServiceBus.ExceptionInfo.Data." + entry.Key] = entry.Value.ToString();
}
}
示例7: SetExceptionHeaders
void SetExceptionHeaders(TransportMessage message, Exception e, string reason)
{
message.Headers["NServiceBus.ExceptionInfo.Reason"] = reason;
message.Headers["NServiceBus.ExceptionInfo.ExceptionType"] = e.GetType().FullName;
if (e.InnerException != null)
message.Headers["NServiceBus.ExceptionInfo.InnerExceptionType"] = e.InnerException.GetType().FullName;
message.Headers["NServiceBus.ExceptionInfo.HelpLink"] = e.HelpLink;
message.Headers["NServiceBus.ExceptionInfo.Message"] = e.GetMessage();
message.Headers["NServiceBus.ExceptionInfo.Source"] = e.Source;
message.Headers["NServiceBus.ExceptionInfo.StackTrace"] = e.StackTrace;
var failedQ = localAddress ?? Address.Local;
message.Headers[FaultsHeaderKeys.FailedQ] = failedQ.ToString();
message.Headers["NServiceBus.TimeOfFailure"] = DateTimeExtensions.ToWireFormattedString(DateTime.UtcNow);
}