kg
6 年前
当前提交
ba624d83
共有 10 个文件被更改,包括 374 次插入 和 87 次删除
-
6Assets/UIWidgets/Tests/Gestures.cs
-
5Assets/UIWidgets/editor/editor_window.cs
-
3Assets/UIWidgets/foundation/basic_types.cs
-
14Assets/UIWidgets/foundation/debug.cs
-
16Assets/UIWidgets/gestures/binding.cs
-
51Assets/UIWidgets/rendering/binding.cs
-
2Assets/UIWidgets/rendering/view.cs
-
217Assets/UIWidgets/scheduler/binding.cs
-
144Assets/UIWidgets/foundation/assertions.cs
-
3Assets/UIWidgets/foundation/assertions.cs.meta
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using Debug = UnityEngine.Debug; |
|||
|
|||
namespace 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.Log(details.ToString()); |
|||
} else { |
|||
Debug.Log("Another exception was thrown: " + details.exceptionAsString()); |
|||
} |
|||
|
|||
_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); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b1c014fd2b864fe696ffb29b063921b4 |
|||
timeCreated: 1536501637 |
撰写
预览
正在加载...
取消
保存
Reference in new issue