本文整理汇总了C#中System.Exception.?.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Exception.?.GetType方法的具体用法?C# Exception.?.GetType怎么用?C# Exception.?.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Exception
的用法示例。
在下文中一共展示了Exception.?.GetType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToError
private static Error ToError(Exception exception)
{
var type = exception?.GetType().FullName ?? "Unknown";
var message = exception?.Message ?? "Unknown error.";
//var dictionary = exception?.Data.Cast<DictionaryEntry>().Where(x => x.Value != null).ToDictionary(item => item.Key.ToString(), item => item.Value.ToString());
var a = new Error
{
Code = 1,
Type = type,
Message = message.Replace(Environment.NewLine, " "),
//Data = dictionary,
};
return a;
}
示例2: ExceptionModel
public ExceptionModel(Exception exception, int number)
{
Number = number;
_exception = exception;
Properties = new List<ExceptionProperty>();
if (exception == null) return;
Properties.Add(new ExceptionProperty("Type", exception.GetType()));
Properties.AddRange(exception?.GetType().GetProperties()
.Where(x => x.Name != nameof(Exception.Data) &&
x.Name != nameof(Exception.InnerException) &&
x.Name != nameof(Exception.HResult))
.Select(x => new ExceptionProperty(x.Name,
x.GetValue(exception)))
.OrderBy(x => x.Name));
}
示例3: Rethrowing
public bool Rethrowing(Exception exception)
{
if (IsErrorEnabled)
{
var msg = $"Rethrowing an exception of type '{exception?.GetType()?.FullName ?? UndefinedExceptionType}'";
WriteInternal(LogLevel.Error, msg, exception);
}
return DoNotFilterException;
}
示例4: Throwing
public void Throwing(Exception exception)
{
if (IsErrorEnabled)
{
var msg = $"Throwing an exception of type '{exception?.GetType()?.FullName ?? UndefinedExceptionType}'";
WriteInternal(LogLevel.Error, msg, exception);
}
}
示例5: ExceptionEquals
private static bool ExceptionEquals(Exception a, Exception b)
{
return a?.GetType() == b?.GetType() &&
a?.Message == b?.Message;
}
示例6: Command_Display_Error
private DialogResult Command_Display_Error(string tryingToDoWhat, string objectsThatFailed = null, Exception ex = null,
string message = null) {
//TODO: Better error dialog
var errorType = "";
if (ex is PatchException) {
errorType = "A patch was invalid, incompatible, or caused an error.";
} else if (ex is IOException) {
errorType = "Related to reading/writing files.";
} else if (ex is ApplicationException) {
errorType = "An application error.";
} else if (ex != null) {
errorType = "A system error or some sort of bug.";
}
var errorString = "An error has occurred,\r\n";
errorString += tryingToDoWhat.IsNullOrWhitespace() ? "" : $"While trying to: {tryingToDoWhat}\r\n";
errorString += errorType.IsNullOrWhitespace() ? "" : $"Error type: {errorType} ({ex?.GetType().Name})\r\n";
errorString += ex == null ? "" : $"Internal message: {ex.Message}\r\n";
errorString += objectsThatFailed.IsNullOrWhitespace() ? "" : $"Object(s) that failed: {objectsThatFailed}\r\n";
errorString += message.IsNullOrWhitespace() ? "" : $"{message}\r\n";
Logger.Error(ex, errorString);
return MessageBox.Show(errorString, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}