本文整理汇总了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);
}
示例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
}
示例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);
}
示例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);
});
}