当前位置: 首页>>代码示例>>C#>>正文


C# Exception.GetMessage方法代码示例

本文整理汇总了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();
            }
        }
开发者ID:Particular,项目名称:NServiceBus,代码行数:32,代码来源:ExceptionHeaderHelper.cs

示例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);
 }
开发者ID:Mygod,项目名称:WoGCursor,代码行数:9,代码来源:App.xaml.cs

示例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;
        }
开发者ID:Xamarui,项目名称:Exceptionless.Net,代码行数:55,代码来源:ToErrorModelExtensions.cs

示例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);
        }
开发者ID:ogdenmd,项目名称:NServiceBus,代码行数:20,代码来源:ExceptionHeaderHelper.cs

示例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();
        }
开发者ID:kjellski,项目名称:async-dolls,代码行数:20,代码来源:FailureHeaderExtensions.cs

示例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();
            }
        }
开发者ID:robvdlv,项目名称:NServiceBus,代码行数:39,代码来源:ExceptionHeaderHelper.cs

示例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);
        }
开发者ID:johannesg,项目名称:NServiceBus,代码行数:18,代码来源:ManageMessageFailuresWithoutSlr.cs


注:本文中的System.Exception.GetMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。