本文整理汇总了C#中System.Exception.IsNull方法的典型用法代码示例。如果您正苦于以下问题:C# Exception.IsNull方法的具体用法?C# Exception.IsNull怎么用?C# Exception.IsNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Exception
的用法示例。
在下文中一共展示了Exception.IsNull方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetError
/// <summary>
/// </summary>
protected static String GetError(Exception ex, Error? error = null)
{
if (ex.IsNull())
return Format(error: error);
if (!ex.InnerException.IsNull())
return Format(ex.InnerException.Message, error);
return Format(ex.Message, error);
}
示例2: Log
public override ILOGGER Log(LEVEL level, string message, Exception ex = null) {
return this.Fluently(_ => {
var type = Mapping[level];
ex
.IsNull()
.IfTrue(() => Diagnostics.Log(type, message))
.IfFalse(() => Diagnostics.Log(type, ex, message));
;
});
}
示例3: SerializeException
static string SerializeException(Exception e, string exceptionMessage)
{
if (e.IsNull()) return string.Empty;
exceptionMessage = "{0}{1}{2}\n{3}".FormatWith(exceptionMessage, exceptionMessage.IsEmpty() ? "" : "\n\n",
e.Message, e.StackTrace);
if (e.InnerException.IsNotNull()) exceptionMessage = SerializeException(e.InnerException, exceptionMessage);
return exceptionMessage;
}
示例4: LogException
public static void LogException(this ILogProvider provider,
Exception exception)
{
var stackFrame = new StackFrame(1, true);
var method = stackFrame.GetMethod();
string memberName = null;
if (method.IsNotNull())
{
memberName = method.Name;
}
var sourceFilePath = stackFrame.GetFileName();
var sourceLineNumber = stackFrame.GetFileLineNumber();
if (exception.IsNull())
{
throw new ArgumentNullException("exception");
}
InternalLogMessage(provider, exception.ToString(), Severity.Error, Verbosity.Normal, memberName, sourceFilePath, sourceLineNumber);
}
示例5: Shutdown
public static void Shutdown(Exception eventArgs = null)
{
sUtilities.RemovePidFile();
sListener.Exit = true;
Console.CursorVisible = true;
if(!eventArgs.IsNull())
{
Log.Error("Main", sLConsole.GetString("An unhandled exception has been thrown. ({0})"), eventArgs.Message);
sCrashDumper.CreateCrashDump(eventArgs);
}
var packet = new SchumixPacket();
packet.Write<int>((int)Opcode.SMSG_CLOSE_CONNECTION);
packet.Write<int>((int)0);
sServerPacketHandler.SendPacketBackAllHost(packet);
Thread.Sleep(2000);
sRuntime.Exit();
}
示例6: _expandException
/// <summary>
/// 显示详细的出错信息
/// </summary>
/// <param name="ex">Exception ex</param>
/// <param name="offSet"></param>
/// <param name="sb"></param>
private static void _expandException(Exception ex, int offSet, StringBuilder sb) {
if (ex.IsNull()) return;
Type t = ex.GetType();
string paddingString = "";
if (offSet > 1) paddingString = new String(' ', offSet * 4);
sb.AppendFormat("{0}Exception: {1}{2}", paddingString, t.Name, Environment.NewLine);
sb.AppendFormat("{0}Message: {1}{2}", paddingString, ex.Message, Environment.NewLine);
sb.AppendFormat("{0}Source: {1}{2}", paddingString, ex.Source, Environment.NewLine);
if (ex.StackTrace.IsNotNull()) sb.AppendFormat("{0}Stack Trace: {1}{2}", paddingString, ex.StackTrace.Trim(), Environment.NewLine);
if (ex.TargetSite.IsNotNull()) sb.AppendFormat("{0}Method: {1}{2}", paddingString, ex.TargetSite.Name, Environment.NewLine);
sb.AppendFormat("{0}Native: {1}{2}", paddingString, ex.ToString(), Environment.NewLine);
sb.AppendFormat("{0}Data: {1}{2}", paddingString, expandData(ex.Data, offSet), Environment.NewLine);
//Exception baseException = ex.GetBaseException();
//if (baseException.IsNotNull()) sb.AppendFormat("{0}Base: {1}{2}", paddingString, ex.GetBaseException(), Environment.NewLine);
_expandException(ex.InnerException, offSet + 1, sb);
}
示例7: SetException
public void SetException(Exception exception)
{
if (exception.IsNull()) return;
;
LastException = exception;
MyCallstackItem.ExceptionMessage = exception.Message;
MyCallstackItem.StackTrace = exception.StackTrace;
}
示例8: Log
public override ILogger Log(LogLevel level, string message, Exception ex = null)
{
return this.Fluently(() => Console.WriteLine(level + ":" + message + (ex.IsNull() ? String.Empty : ", exception: " + ex.ToString())));
}