您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

144 行
4.6 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Debug = UnityEngine.Debug;
namespace Unity.UIWidgets.foundation {
public delegate void UIWidgetsExceptionHandler(UIWidgetsErrorDetails details);
public delegate void InformationCollector(StringBuilder information);
public class UIWidgetsErrorDetails {
public UIWidgetsErrorDetails(
Exception exception = null,
string library = "UIWidgets framework",
string context = null,
EnumerableFilter<String> stackFilter = null,
InformationCollector informationCollector = null,
bool silent = false
) {
this.exception = exception;
this.library = library;
this.context = context;
this.stackFilter = stackFilter;
this.informationCollector = informationCollector;
this.silent = silent;
}
public readonly Exception exception;
public readonly string library;
public readonly string context;
public readonly EnumerableFilter<String> stackFilter;
public readonly InformationCollector informationCollector;
public readonly bool silent;
public string exceptionAsString() {
string longMessage = null;
if (this.exception != null) {
longMessage = this.exception.Message;
}
if (longMessage != null) {
longMessage = longMessage.TrimEnd();
}
if (longMessage.isEmpty()) {
longMessage = "<no message available>";
}
return longMessage;
}
public override string ToString() {
var buffer = new StringBuilder();
if (this.library.isNotEmpty() || this.context.isNotEmpty()) {
if (this.library.isNotEmpty()) {
buffer.AppendFormat("Error caught by {0}", this.library);
if (this.context.isNotEmpty()) {
buffer.Append(", ");
}
} else {
buffer.Append("Exception ");
}
if (this.context.isNotEmpty()) {
buffer.AppendFormat("thrown {0}", this.context);
}
buffer.Append(". ");
} else {
buffer.Append("An error was caught. ");
}
buffer.AppendLine(this.exceptionAsString());
if (this.informationCollector != null) {
this.informationCollector(buffer);
}
if (this.exception.StackTrace != null) {
IEnumerable<string> stackLines = this.exception.StackTrace.TrimEnd().Split('\n');
if (this.stackFilter != null) {
stackLines = this.stackFilter(stackLines);
} else {
stackLines = UIWidgetsError.defaultStackFilter(stackLines);
}
buffer.Append(string.Join("\n", stackLines.ToArray()));
}
return buffer.ToString().TrimEnd();
}
}
public class UIWidgetsError : AssertionError {
public UIWidgetsError(string message) : base(message) {
}
public static UIWidgetsExceptionHandler onError = dumpErrorToConsole;
static int _errorCount = 0;
public static void resetErrorCount() {
_errorCount = 0;
}
public static void dumpErrorToConsole(UIWidgetsErrorDetails details) {
dumpErrorToConsole(details, forceReport: false);
}
public static void dumpErrorToConsole(UIWidgetsErrorDetails details, bool forceReport = false) {
D.assert(details != null);
D.assert(details.exception != null);
bool reportError = !details.silent;
D.assert(() => {
reportError = true;
return true;
});
if (!reportError && !forceReport) {
return;
}
if (_errorCount == 0 || forceReport) {
Debug.LogError(details.ToString());
} else {
Debug.LogWarning("Another exception was thrown: " + details);
}
_errorCount += 1;
}
public static IEnumerable<string> defaultStackFilter(IEnumerable<string> frames) {
return frames;
}
public static void reportError(UIWidgetsErrorDetails details) {
D.assert(details != null);
D.assert(details.exception != null);
if (onError != null) {
onError(details);
}
}
}
}