本文整理汇总了C#中System.Exception.IsNotNull方法的典型用法代码示例。如果您正苦于以下问题:C# Exception.IsNotNull方法的具体用法?C# Exception.IsNotNull怎么用?C# Exception.IsNotNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Exception
的用法示例。
在下文中一共展示了Exception.IsNotNull方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PreProcess
private static void PreProcess(Severity severity, string additionalMessage, Exception exception)
{
var callStack = new StackTrace(1, true);
var stackFrame = callStack.GetFrame(1);
var log = new Log
{
MethodName = stackFrame.GetMethod().Name,
ClassName = stackFrame.GetMethod().DeclaringType.Name,
ApplicationName = stackFrame.GetMethod().DeclaringType.Assembly.GetName().Name,
LineNumber = stackFrame.GetFileLineNumber(),
Severity = (int)severity,
Message = $"Message: {additionalMessage ?? ""}"
};
if (exception.IsNotNull())
{
log.Message += $" Exception: {(exception.IsNotNull() ? exception.ToString() : "")}";
}
using (var ctx = new ApplicationDbContext())
{
ctx.Logs.Add(log);
ctx.SaveChanges();
}
}
示例2: FormatException
/// <summary>
/// Formats an exception to be placed in the debug output.
/// </summary>
/// <param name="ex">
/// The exception.
/// </param>
/// <returns>
/// A string that represents the message to display for the exception.
/// </returns>
protected string FormatException(Exception ex)
{
var builder = new StringBuilder();
if (ex.IsNotNull())
{
builder.AppendLine(ex.Message);
builder.AppendLine(ex.StackTrace);
var aggex = ex as AggregateException;
if (aggex.IsNotNull())
{
foreach (Exception innerException in aggex.InnerExceptions)
{
builder.AppendLine(this.FormatException(innerException));
}
}
else if (ex.InnerException.IsNotNull())
{
builder.AppendLine(this.FormatException(ex.InnerException));
}
}
return builder.ToString();
}
示例3: IsFatalException
private bool IsFatalException(Exception e)
{
var fatalTypes = new List<Type> { typeof(ArgumentException) };
bool rv = false;
if (e.IsNotNull())
{
Exception finalException = GetFirstException(e);
Type exceptionType = finalException.GetType();
foreach (Type t in fatalTypes)
{
if (t.IsAssignableFrom(exceptionType))
{
rv = true;
break;
}
}
}
return rv;
}