{"id":2615,"date":"2023-05-10T19:42:48","date_gmt":"2023-05-10T11:42:48","guid":{"rendered":"https:\/\/www.clonefactor.com\/wordpress\/?p=2615"},"modified":"2023-05-10T19:42:49","modified_gmt":"2023-05-10T11:42:49","slug":"debug%ef%bc%9a%e6%b7%b1%e5%85%a5%e6%9f%a5%e7%9c%8binner-exception","status":"publish","type":"post","link":"https:\/\/www.clonefactor.com\/wordpress\/program\/2615\/","title":{"rendered":"Debug\uff1a\u6df1\u5165\u67e5\u770bInner Exception"},"content":{"rendered":"\n<p>\u5728\u8edf\u4ef6\u958b\u767c\u904e\u7a0b\u4e2d\uff0c\u6211\u5011\u7d93\u5e38\u6703\u9047\u5230\u7570\u5e38\u60c5\u6cc1\u3002\u7576\u7570\u5e38\u767c\u751f\u6642\uff0c\u4e86\u89e3\u7570\u5e38\u7684\u8a73\u7d30\u4fe1\u606f\u548c\u5b83\u7684\u5167\u90e8\u7570\u5e38\uff08Inner Exception\uff09\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u5167\u90e8\u7570\u5e38\u63d0\u4f9b\u4e86\u7570\u5e38\u93c8\u4e2d\u66f4\u6df1\u5c64\u6b21\u7684\u4e0a\u4e0b\u6587\uff0c\u5e6b\u52a9\u6211\u5011\u66f4\u597d\u5730\u7406\u89e3\u548c\u89e3\u6c7a\u554f\u984c\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u4e00\u7a2e\u65b9\u6cd5\uff0c\u901a\u904e\u4f7f\u7528DeepLogInvocationException\u51fd\u6578\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8a18\u9304\u4e26\u67e5\u770b\u7570\u5e38\u93c8\u4e2d\u6bcf\u500b\u5167\u90e8\u7570\u5e38\u7684\u8a73\u7d30\u4fe1\u606f\u3002<\/p>\n<p>\u5728Unity 2021.2.0a11\u7248\u672c\u4e2d\uff0c\u6211\u5011\u53ef\u4ee5\u5229\u7528\u5176\u7279\u6027\uff0c\u76f4\u63a5\u5728Unity3D\u63a7\u5236\u53f0\u4e2d\u6253\u958b\u8207\u7570\u5e38\u76f8\u95dc\u7684\u6587\u4ef6\uff0c\u4e26\u8df3\u8f49\u5230\u7570\u5e38\u767c\u751f\u7684\u884c\u865f\u3002\u9019\u70ba\u6211\u5011\u8abf\u8a66\u7570\u5e38\u63d0\u4f9b\u4e86\u4fbf\u5229\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u5011\u4f86\u770b\u4e00\u4e0bHyperlink\u51fd\u6578\u7684\u5be6\u73fe\u3002\u5b83\u662f\u4e00\u500b\u64f4\u5c55\u65b9\u6cd5\uff0c\u7528\u65bc\u5c07\u6587\u672c\u6a19\u8a18\u70ba\u8d85\u93c8\u63a5\u4e26\u63d0\u4f9b\u93c8\u63a5\u5730\u5740\u3002\u5728\u6211\u5011\u7684\u65b9\u6cd5\u4e2d\uff0c\u6211\u5011\u4f7f\u7528\u4e86\u5169\u500b\u91cd\u8f09\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">public static string Hyperlink(this string tag, string url)\n{\n    return $\"&lt;a href=\\\"{url}\\\"&gt;{tag}&lt;\/a&gt;\";\n}\n\npublic static string Hyperlink(this string tag, string url, int line)\n{\n    return $\"&lt;a href=\\\"{url}\\\" line=\\\"{line}\\\"&gt;{tag}&lt;\/a&gt;\";\n}\n<\/pre>\n<p>\u63a5\u4e0b\u6765\uff0c\u8ba9\u6211\u4eec\u770b\u4e00\u4e0b<code>DeepLogInvocationException<\/code>\u51fd\u6570\u7684\u5b9e\u73b0\u3002\u5b83\u662f\u4e00\u4e2a\u6269\u5c55\u65b9\u6cd5\uff0c\u7528\u4e8e\u5728\u4e8b\u4ef6\u8c03\u5ea6\u8fc7\u7a0b\u4e2d\u8c03\u8bd5\u5f02\u5e38\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">public static void DeepLogInvocationException(this Exception ex, string delegateName, int skipDepth = 0)\n{\n    int skip = Mathf.Max(0, skipDepth);\n    int atLeastOne = 0;\n    StringBuilder sb = new StringBuilder();\n    Exception orgEx = ex;\n    while (ex is not null)\n    {\n        StackTrace trace = new(ex, true);\n\n        if (skip &lt;= 0)\n        {\n            var errorType   = ex.GetType().Name;\n            for (var i = 0; i &lt; trace.FrameCount; ++i)\n            {\n                if (TryGetFrameInfo(trace.GetFrame(i), out var info))\n                {\n                    sb.AppendLine(info);\n                }\n            }\n\n            AxDebug.LogError($\"[{delegateName}] -&gt; {errorType}:\\n{ex.Message}\\n{sb.ToString()}\\n\\n{ex.StackTrace}\\n\");\n            ++atLeastOne;\n        }\n        --skip;\n        ex = ex.InnerException;\n    }\n\n    \/\/ Fall back when no exception was logged\n    if (atLeastOne == 0)\n        AxDebug.LogError($\"Exception during {delegateName} &lt; {orgEx.Message}\\n{orgEx.StackTrace}\\n\");\n\n\n    bool TryGetFrameInfo(StackFrame frame, out string info)\n    {\n        info = null;\n        if (frame == null)\n            return false;\n        var filePath    = frame.GetFileName();\n        if (filePath == null || filePath.Length == 0)\n            return false;\n        var fileName    = System.IO.Path.GetFileName(filePath);\n        var lineNo      = frame.GetFileLineNumber();\n        var methodName  = frame.GetMethod().GetFullName();\n        var tag         = $\"{fileName} &gt; {methodName}\";\n        info = $\"{tag.Hyperlink(filePath, lineNo)}:Line {lineNo}\";\n        return true;\n    }\n}<\/pre>\n<p>\u00a0<\/p>\n\n\n\n<p>\u4f7f\u7528\u4e0a\u8ff0\u8655\u7406\u65b9\u5f0f\u7684\u597d\u8655\u548c\u58de\u8655\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>\u597d\u8655\uff1a<\/p>\n\n\n\n<p>\u8a73\u7d30\u7684\u7570\u5e38\u4fe1\u606f\uff1aDeepLogInvocationException\u51fd\u6578\u5141\u8a31\u8a18\u9304\u7570\u5e38\u93c8\u4e2d\u6bcf\u500b\u5167\u90e8\u7570\u5e38\u7684\u8a73\u7d30\u4fe1\u606f\uff0c\u5305\u62ec\u7570\u5e38\u985e\u578b\u3001\u6d88\u606f\u548c\u5806\u68e7\u8ddf\u8e64\u3002\u9019\u6a23\u53ef\u4ee5\u63d0\u4f9b\u66f4\u8c50\u5bcc\u7684\u8abf\u8a66\u4fe1\u606f\uff0c\u5e6b\u52a9\u958b\u767c\u4eba\u54e1\u5b9a\u4f4d\u548c\u89e3\u6c7a\u554f\u984c\u3002<\/p>\n\n\n\n<p>\u7570\u5e38\u8abf\u8a66\u7684\u4fbf\u5229\u6027\uff1a\u901a\u904e\u5728Unity3D\u63a7\u5236\u53f0\u4e2d\u6253\u958b\u8207\u7570\u5e38\u76f8\u95dc\u7684\u6587\u4ef6\u4e26\u8df3\u8f49\u5230\u7570\u5e38\u767c\u751f\u7684\u884c\u865f\uff0c\u6211\u5011\u53ef\u4ee5\u66f4\u65b9\u4fbf\u5730\u8abf\u8a66\u7570\u5e38\u3002\u9019\u5728\u5fa9\u96dc\u7684\u4ee3\u78bc\u908f\u8f2f\u4e2d\u7279\u5225\u6709\u7528\uff0c\u53ef\u4ee5\u6e1b\u5c11\u624b\u52d5\u67e5\u627e\u548c\u8ffd\u8e64\u7570\u5e38\u7684\u5de5\u4f5c\u91cf\u3002<\/p>\n\n\n\n<p>\u5167\u90e8\u7570\u5e38\u7684\u8655\u7406\uff1a\u7570\u5e38\u93c8\u4e2d\u7684\u5167\u90e8\u7570\u5e38\u63d0\u4f9b\u4e86\u66f4\u6df1\u5c64\u6b21\u7684\u4e0a\u4e0b\u6587\u4fe1\u606f\uff0c\u5e6b\u52a9\u6211\u5011\u4e86\u89e3\u7570\u5e38\u7684\u539f\u56e0\u548c\u767c\u751f\u4f4d\u7f6e\u3002\u901a\u904e\u8a18\u9304\u4e26\u8655\u7406\u5167\u90e8\u7570\u5e38\uff0c\u6211\u5011\u53ef\u4ee5\u66f4\u597d\u5730\u8ffd\u8e64\u7570\u5e38\u7684\u6e90\u982d\uff0c\u4e26\u91c7\u53d6\u9069\u7576\u7684\u63aa\u65bd\u9032\u884c\u4fee\u5fa9\u3002<\/p>\n\n\n\n<p>\u58de\u8655\uff1a<\/p>\n\n\n\n<p>\u4fe1\u606f\u91cd\u5fa9\u8f38\u51fa\uff1a\u5982\u679c\u7570\u5e38\u93c8\u8f03\u9577\u4e14\u6709\u591a\u500b\u5167\u90e8\u7570\u5e38\uff0c\u53ef\u80fd\u6703\u5c0e\u81f4\u91cd\u5fa9\u8f38\u51fa\u76f8\u540c\u7684\u7570\u5e38\u4fe1\u606f\u3002\u9019\u53ef\u80fd\u6703\u5728\u65e5\u5fd7\u4e2d\u7522\u751f\u5197\u4f59\u4fe1\u606f\uff0c\u589e\u52a0\u65e5\u5fd7\u6587\u4ef6\u7684\u5927\u5c0f\u3002<\/p>\n\n\n\n<p>\u53ef\u80fd\u5f71\u97ff\u6027\u80fd\uff1a\u5728\u904d\u6b77\u7570\u5e38\u93c8\u4e26\u8a18\u9304\u7570\u5e38\u4fe1\u606f\u6642\uff0c\u53ef\u80fd\u6703\u5f15\u5165\u4e00\u5b9a\u7684\u6027\u80fd\u958b\u92b7\u3002\u7279\u5225\u662f\u5728\u7570\u5e38\u93c8\u8f03\u9577\u6216\u7570\u5e38\u8655\u7406\u983b\u7e41\u7684\u60c5\u6cc1\u4e0b\uff0c\u53ef\u80fd\u6703\u5c0d\u61c9\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u7522\u751f\u8f15\u5fae\u5f71\u97ff\u3002<\/p>\n\n\n\n<p>\u7d9c\u4e0a\u6240\u8ff0\uff0c\u4f7f\u7528DeepLogInvocationException\u51fd\u6578\u53ef\u4ee5\u63d0\u4f9b\u66f4\u8c50\u5bcc\u7684\u8abf\u8a66\u4fe1\u606f\u548c\u7570\u5e38\u8655\u7406\u80fd\u529b\uff0c\u4f46\u9700\u8981\u6ce8\u610f\u907f\u514d\u5197\u4f59\u8f38\u51fa\u548c\u53ef\u80fd\u7684\u6027\u80fd\u5f71\u97ff\u3002\u5728\u958b\u767c\u904e\u7a0b\u4e2d\uff0c\u6839\u64da\u5177\u9ad4\u60c5\u6cc1\u548c\u9700\u6c42\uff0c\u53ef\u4ee5\u6b0a\u8861\u5229\u5f0a\u4e26\u9032\u884c\u9069\u7576\u7684\u4f7f\u7528\u548c\u8abf\u6574\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u8edf\u4ef6\u958b\u767c\u904e\u7a0b\u4e2d\uff0c\u6211\u5011\u7d93\u5e38\u6703\u9047\u5230\u7570\u5e38\u60c5\u6cc1\u3002\u7576\u7570\u5e38\u767c\u751f\u6642\uff0c\u4e86\u89e3\u7570\u5e38\u7684\u8a73\u7d30\u4fe1\u606f\u548c\u5b83\u7684\u5167\u90e8\u7570\u5e38\uff08Inner &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,11,4],"tags":[125],"class_list":["post-2615","post","type-post","status-publish","format-standard","hentry","category-c","category-unity3d","category-program","tag-debug"],"_links":{"self":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts\/2615","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/comments?post=2615"}],"version-history":[{"count":1,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts\/2615\/revisions"}],"predecessor-version":[{"id":2616,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts\/2615\/revisions\/2616"}],"wp:attachment":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/media?parent=2615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/categories?post=2615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/tags?post=2615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}