當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。