差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

rf:rf:debug:trace_exception_of_javalib [2019/06/29 23:20]
tony [How to?]
rf:rf:debug:trace_exception_of_javalib [2023/06/25 09:48]
行 1: 行 1:
-{{tag>​RobotFramework}} 
-====== RobotFramework - How to trace the exception of java keyword library? ====== 
-===== Problem ===== 
-使用java based開發robot keyword的人,大都會遇到發生非預期例外時,不知道root cause在哪,因為你拿到的訊息通常如下:​\\ 
-{{:​rf:​rf:​debug:​nullpointerexception_of_robot.png|}}\\ 
-\\ 
-今天在review前同事的東西時,就遇到了這個問題! 我將分享兩個方法給大家,該如何去拿到詳細的callstack或message。 
-===== How to? ===== 
-==== Run with debug mode ==== 
-在不修改任何程式碼的情況下,請將以下參數加到你Robot啟動參數中:​ 
-<code bash> 
---loglevel DEBUG 
-</​code>​ 
-以我的ride為例,會像這樣子:​\\ 
-{{:​rf:​rf:​debug:​launch_rf_with_debug_level.png|}}\\ 
-\\ 
-假如有問題的程式再執行一次,就能看到以下內容:​\\ 
-{{:​rf:​rf:​debug:​stacktrace_of_report.png|}}\\ 
-\\ 
-有了這個callstack以後,相信可以幫助你減少許多追蹤問題的時間。 
-==== Catch exception and apply logger ==== 
-前面的方式適用於問題容易被重現的情況,假如你是偶爾發生問題,就要考慮預先把例外捕捉起來且做Log。在透過java開發robot keyword時,如果你使用以下寫法,會被當作INFO level: 
-<code java> 
-System.out.println(e.getMessage());​ 
-</​code>​ 
-INFO level預設情況下,是可以讓你在報表中看到你想要呈現的結果(callstack or exception message);但語意是不是怪怪的呢?​ 上面那個寫法,等效於:​ 
-<code java> 
-System.out.println("​*INFO* " + e.getMessage());​ 
-</​code>​ 
-如果你要讓語意清楚點,可以選擇寫成這樣:​ 
-<code java> 
-System.out.println("​*WARN* " + e.getMessage());​ 
-System.out.println("​*ERROR* " + e.getMessage());​ 
-</​code>​ 
-這個logger方式,可以放在你catch exception後,將callstack或者message印出。假如嫌這個寫法不夠漂亮,更進一步,你可以考慮與log4j或者是java Logger api做整合。 
  
-===== Reference ===== 
-  * [[https://​groups.google.com/​forum/#​!topic/​robotframework-users/​bQCI1wHR8do|How to pring/log the build-in exception stack trace?]] 
-  * [[https://​robotframework.org/​robotframework/​latest/​RobotFrameworkUserGuide.html#​public-logging-api|RobotFramework UserGuide - Programmatic logging APIs]] 
- 
-=====    ===== 
----- 
-\\ 
-~~DISQUS~~