{"id":35775,"date":"2024-11-26T12:23:30","date_gmt":"2024-11-26T04:23:30","guid":{"rendered":"https:\/\/fwq.ai\/blog\/35775\/"},"modified":"2024-11-26T12:23:30","modified_gmt":"2024-11-26T04:23:30","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88-debug-%e6%97%b6%e4%bc%9a%e8%b7%b3%e8%bf%87%e6%96%b9%e6%b3%95%e8%b0%83%e7%94%a8%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/35775\/","title":{"rendered":"\u4e3a\u4ec0\u4e48 Debug \u65f6\u4f1a\u8df3\u8fc7\u65b9\u6cd5\u8c03\u7528\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173072700447680.jpg\" class=\"aligncenter\" title=\"\u4e3a\u4ec0\u4e48 Debug \u65f6\u4f1a\u8df3\u8fc7\u65b9\u6cd5\u8c03\u7528\uff1f\u63d2\u56fe\" alt=\"\u4e3a\u4ec0\u4e48 Debug \u65f6\u4f1a\u8df3\u8fc7\u65b9\u6cd5\u8c03\u7528\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u4e3a\u4ec0\u4e48 debug \u65f6\u4e0d\u4f1a\u8fdb\u5165\u8c03\u7528\u7684\u65b9\u6cd5\uff1f<\/strong><\/p>\n<p>\u5728\u8c03\u8bd5\u8fc7\u7a0b\u4e2d\uff0c\u65ad\u70b9\u4f1a\u81ea\u52a8\u8df3\u8fc7\u67d0\u4e9b\u65b9\u6cd5\u7684\u8c03\u7528\u3002\u5f53\u4ee3\u7801\u6267\u884c\u5230\u6807\u6ce8\u65ad\u70b9\u884c\u65f6\uff0c\u901a\u5e38\u4f1a\u7acb\u5373\u89e6\u53d1\u65ad\u70b9\u5e76\u505c\u6b62\u6267\u884c\uff0c\u4e0d\u4f1a\u8fdb\u5165\u540e\u7eed\u65b9\u6cd5\u4e2d\u3002<\/p>\n<p><strong>\u793a\u4f8b\u60c5\u51b5\uff1a<\/strong><\/p>\n<p>\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u4ee3\u7801\u5728 callme() \u65b9\u6cd5\u4e2d\u62a5\u7a7a\u6307\u9488\u5f02\u5e38\u3002\u7136\u800c\uff0c\u5728\u8c03\u8bd5\u8fd0\u884c\u65f6\uff0c\u65ad\u70b9\u76f4\u63a5\u5728\u62a5\u9519\u884c\u505c\u6b62\uff0c\u65e0\u6cd5\u8fdb\u5165 dosomething() \u65b9\u6cd5\u8fdb\u884c\u8c03\u8bd5\u3002<\/p>\n<pre>void callme() {\n  dosomething();  \/\/ \u62a5\u7a7a\u6307\u9488\u5f02\u5e38\n}\n\nvoid dosomething() {\n  \/\/ \u4ee3\u7801\u7701\u7565\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u539f\u56e0\uff1a<\/strong><\/p>\n<p>\u4ee3\u7801\u5757\u6267\u884c\u65f6\uff0c\u865a\u62df\u673a\u5c06\u65b9\u6cd5\u51fd\u6570\u7684\u53c2\u6570\u53ca\u5c40\u90e8\u53d8\u91cf\u538b\u5165\u6808\u4e2d\u3002\u5f53\u65b9\u6cd5\u8c03\u7528\u65f6\uff0c\u65b0\u7684\u65b9\u6cd5\u51fd\u6570\u7684\u53c2\u6570\u53ca\u5c40\u90e8\u53d8\u91cf\u4f1a\u538b\u5165\u65b0\u7684\u6808\u5e27\u4e2d\u3002<\/p>\n<p>\u5f53\u5f02\u5e38\u53d1\u751f\u65f6\uff0c\u865a\u62df\u673a\u4f1a\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li> <strong>\u56de\u6eaf\u6808\u5e27\uff1a<\/strong>\u4ece\u5f53\u524d\u6808\u5e27\u56de\u6eaf\u5230\u5f02\u5e38\u53d1\u751f\u65f6\u7684\u6808\u5e27\u3002<\/li>\n<li> <strong>\u6e05\u9664\u5c40\u90e8\u53d8\u91cf\uff1a<\/strong>\u6e05\u7406\u5f53\u524d\u6808\u5e27\u4e2d\u7684\u6240\u6709\u5c40\u90e8\u53d8\u91cf\uff0c\u5305\u62ec\u65b9\u6cd5\u53c2\u6570\u3002<\/li>\n<li> <strong>\u629b\u51fa\u5f02\u5e38\uff1a<\/strong>\u5c06\u5f02\u5e38\u5bf9\u8c61\u629b\u51fa\u5230\u4e0a\u7ea7\u6808\u5e27\u3002<\/li>\n<\/ol>\n<p><strong>\u89e3\u91ca\uff1a<\/strong><\/p>\n<p>\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u7531\u4e8e\u5f02\u5e38\u53d1\u751f\u5728 dosomething() \u65b9\u6cd5\u4e2d\uff0c\u865a\u62df\u673a\u4f1a\u56de\u6eaf\u5230 callme() \u65b9\u6cd5\u7684\u6808\u5e27\u3002\u6b64\u65f6\uff0cdosomething() \u65b9\u6cd5\u7684\u5c40\u90e8\u53d8\u91cf\u5df2\u7ecf\u88ab\u6e05\u9664\uff0c\u5305\u62ec\u8c03\u7528\u7684 this \u5bf9\u8c61\uff0c\u56e0\u6b64\u5f15\u53d1\u7a7a\u6307\u9488\u5f02\u5e38\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u4e3a\u4e86\u80fd\u591f\u5728\u8c03\u8bd5\u8fc7\u7a0b\u4e2d\u8fdb\u5165\u8c03\u7528\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5728 callme() \u65b9\u6cd5\u4e2d\u4f7f\u7528 try-catch \u5757\u6355\u83b7\u5f02\u5e38\uff0c\u5e76\u624b\u52a8\u901a\u8fc7 printstacktrace() \u65b9\u6cd5\u6253\u5370\u5f02\u5e38\u4fe1\u606f\u3002\u8fd9\u6837\u53ef\u4ee5\u4fdd\u7559 dosomething() \u65b9\u6cd5\u7684\u6808\u5e27\u548c\u5c40\u90e8\u53d8\u91cf\uff0c\u4ece\u800c\u65b9\u4fbf\u8c03\u8bd5\u3002<\/p>\n<pre>void CallMe() {\n  try {\n    DoSomething();\n  } catch (Exception e) {\n    e.printStackTrace();\n  }\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4e3a\u4ec0\u4e48 Debug \u65f6\u4f1a\u8df3\u8fc7\u65b9\u6cd5\u8c03\u7528\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u4ec0\u4e48 debug \u65f6\u4e0d\u4f1a\u8fdb\u5165\u8c03\u7528\u7684\u65b9\u6cd5\uff1f \u5728\u8c03\u8bd5\u8fc7\u7a0b\u4e2d\uff0c\u65ad\u70b9\u4f1a\u81ea\u52a8\u8df3\u8fc7\u67d0\u4e9b\u65b9\u6cd5\u7684\u8c03\u7528\u3002\u5f53\u4ee3\u7801\u6267\u884c\u5230\u6807\u6ce8\u65ad\u70b9\u884c\u65f6\uff0c\u901a\u5e38\u4f1a\u7acb\u5373\u89e6\u53d1\u65ad\u70b9\u5e76\u505c\u6b62\u6267\u884c\uff0c\u4e0d\u4f1a\u8fdb\u5165\u540e\u7eed\u65b9\u6cd5\u4e2d\u3002 \u793a\u4f8b\u60c5\u51b5\uff1a \u5982\u4e0b\u56fe\u6240\u793a\uff0c\u4ee3\u7801\u5728 callme() \u65b9\u6cd5\u4e2d\u62a5\u7a7a\u6307\u9488\u5f02\u5e38\u3002\u7136\u800c\uff0c\u5728\u8c03\u8bd5\u8fd0\u884c\u65f6\uff0c\u65ad\u70b9\u76f4\u63a5\u5728\u62a5\u9519\u884c\u505c\u6b62\uff0c\u65e0\u6cd5\u8fdb\u5165 dosomething() \u65b9\u6cd5\u8fdb\u884c\u8c03\u8bd5\u3002 void callme() { dosomething(); \/\/ \u62a5\u7a7a\u6307\u9488\u5f02\u5e38 } void dosomething() { \/\/ \u4ee3\u7801\u7701\u7565 } \u767b\u5f55\u540e\u590d\u5236 \u539f\u56e0\uff1a \u4ee3\u7801\u5757\u6267\u884c\u65f6\uff0c\u865a\u62df\u673a\u5c06\u65b9\u6cd5\u51fd\u6570\u7684\u53c2\u6570\u53ca\u5c40\u90e8\u53d8\u91cf\u538b\u5165\u6808\u4e2d\u3002\u5f53\u65b9\u6cd5\u8c03\u7528\u65f6\uff0c\u65b0\u7684\u65b9\u6cd5\u51fd\u6570\u7684\u53c2\u6570\u53ca\u5c40\u90e8\u53d8\u91cf\u4f1a\u538b\u5165\u65b0\u7684\u6808\u5e27\u4e2d\u3002 \u5f53\u5f02\u5e38\u53d1\u751f\u65f6\uff0c\u865a\u62df\u673a\u4f1a\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u56de\u6eaf\u6808\u5e27\uff1a\u4ece\u5f53\u524d\u6808\u5e27\u56de\u6eaf\u5230\u5f02\u5e38\u53d1\u751f\u65f6\u7684\u6808\u5e27\u3002 \u6e05\u9664\u5c40\u90e8\u53d8\u91cf\uff1a\u6e05\u7406\u5f53\u524d\u6808\u5e27\u4e2d\u7684\u6240\u6709\u5c40\u90e8\u53d8\u91cf\uff0c\u5305\u62ec\u65b9\u6cd5\u53c2\u6570\u3002 \u629b\u51fa\u5f02\u5e38\uff1a\u5c06\u5f02\u5e38\u5bf9\u8c61\u629b\u51fa\u5230\u4e0a\u7ea7\u6808\u5e27\u3002 \u89e3\u91ca\uff1a \u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u7531\u4e8e\u5f02\u5e38\u53d1\u751f\u5728 dosomething() \u65b9\u6cd5\u4e2d\uff0c\u865a\u62df\u673a\u4f1a\u56de\u6eaf\u5230 callme() \u65b9\u6cd5\u7684\u6808\u5e27\u3002\u6b64\u65f6\uff0cdosomething() \u65b9\u6cd5\u7684\u5c40\u90e8\u53d8\u91cf\u5df2\u7ecf\u88ab\u6e05\u9664\uff0c\u5305\u62ec\u8c03\u7528\u7684 this \u5bf9\u8c61\uff0c\u56e0\u6b64\u5f15\u53d1\u7a7a\u6307\u9488\u5f02\u5e38\u3002 \u89e3\u51b3\u65b9\u6848\uff1a \u4e3a\u4e86\u80fd\u591f\u5728\u8c03\u8bd5\u8fc7\u7a0b\u4e2d\u8fdb\u5165\u8c03\u7528\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5728 callme() \u65b9\u6cd5\u4e2d\u4f7f\u7528 try-catch \u5757\u6355\u83b7\u5f02\u5e38\uff0c\u5e76\u624b\u52a8\u901a\u8fc7 printstacktrace() \u65b9\u6cd5\u6253\u5370\u5f02\u5e38\u4fe1\u606f\u3002\u8fd9\u6837\u53ef\u4ee5\u4fdd\u7559 dosomething() \u65b9\u6cd5\u7684\u6808\u5e27\u548c\u5c40\u90e8\u53d8\u91cf\uff0c\u4ece\u800c\u65b9\u4fbf\u8c03\u8bd5\u3002 void CallMe() { try { DoSomething(); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-35775","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35775","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=35775"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35775\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=35775"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=35775"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=35775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}