當前位置: 首頁>>代碼示例>>C#>>正文


C# Exception.NullReference方法代碼示例

本文整理匯總了C#中System.Exception.NullReference方法的典型用法代碼示例。如果您正苦於以下問題:C# Exception.NullReference方法的具體用法?C# Exception.NullReference怎麽用?C# Exception.NullReference使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Exception的用法示例。


在下文中一共展示了Exception.NullReference方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Handle

        /// <summary>
        /// Processes unhandled exceptions.
        /// </summary>
        /// <param name="exception">The unhandled exception to process.</param>
        public void Handle( Exception exception )
        {
            if( exception.NullReference() )
                return;

            AppCore.Log.Error("Unhandled exception caught!", exception);
        }
開發者ID:MechanicalMen,項目名稱:Mechanical2,代碼行數:11,代碼來源:LogExceptionSink.cs

示例2: Handle

        /// <summary>
        /// Processes unhandled exceptions.
        /// </summary>
        /// <param name="exception">The unhandled exception to process.</param>
        public void Handle( Exception exception )
        {
            if( exception.NullReference() )
                return;

            // NOTE: SafeString should be fool-proof, but in case we encounter a bug in it
            //       at the worst moment, let's report it as well
            string str;
            try
            {
                str = "Unhandled exception caught:" + Environment.NewLine + SafeString.DebugPrint(exception);
            }
            catch( Exception safeStringException )
            {
                var sb = new StringBuilder();
                sb.AppendLine("Unhandled exception caught:");
                sb.AppendLine(exception.ToString());
                sb.AppendLine();
                sb.AppendLine("Error encountered while logging the exception:");
                sb.AppendLine(safeStringException.ToString());
                str = sb.ToString();
            }

#if !SILVERLIGHT
            // Unlike Debug, Trace remains in Release builds
            Trace.WriteLine(str);
            Trace.Flush();
#else
            Debug.WriteLine(str);
#endif
        }
開發者ID:MechanicalMen,項目名稱:Mechanical2,代碼行數:35,代碼來源:TraceExceptionSink.cs

示例3: Log

 private void Log(
     LogLevel level,
     string message,
     Exception ex = null,
     [CallerFilePath] string filePath = "",
     [CallerMemberName] string memberName = "",
     [CallerLineNumber] int lineNumber = 0 )
 {
     var info = ex.NullReference() ? null : ExceptionInfo.From(ex);
     var entry = new LogEntry(level, message, info, filePath, memberName, lineNumber);
     this.Log(entry);
 }
開發者ID:MechanicalMen,項目名稱:Mechanical2,代碼行數:12,代碼來源:LogBase.cs

示例4: Handle

        /// <summary>
        /// Processes unhandled exceptions.
        /// </summary>
        /// <param name="exception">The unhandled exception to process.</param>
        public void Handle( Exception exception )
        {
            if( exception.NullReference() )
                return;

            UI.Invoke(() =>
            {
                MessageBox.Show(
                    SafeString.DebugFormat("An unhandled exception of type '{0}' was caught and logged!", exception.GetType()),
                    "Unhandled exception!",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
            });
        }
開發者ID:MechanicalMen,項目名稱:Mechanical2,代碼行數:18,代碼來源:MessageBoxExceptionSink.cs


注:本文中的System.Exception.NullReference方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。