2011-07-21 54 views
1

是否有可能獲得包含在堆棧跟蹤中的變量值?使用bugsense哪些電子郵件堆棧跟蹤我,我剛剛開始,我不知道是否有在我的代碼中的一些方式把變量的值到堆棧跟蹤輸出堆棧跟蹤和變量值

回答

0

缺省情況下,你必須自己做:

堆棧跟蹤將只會告訴您有關所涉及的代碼行(其中Exception被拋出)和執行堆棧。

但沒有阻止你捕捉Exception,並在郵件中包含一些調試信息:

try { 
    ...the code... 
} 
catch (Throwable t) { 
    // Here, we catch any Throwable (Exception but also Error such as OutOfMemory 
    // or NoClassDefFound), which is *absolutely not suitable* for 
    // anything else than debugging. 
    // You can (should, actually) make this catch statement more specific 
    // depending of the Exception or Error you are facing 

    // Dump your variables here: 
    final String message = "myVar=" + myVar; 

    // The statement below rethrows the original Throwable and adds your 
    // own message to it 
    throw new RuntimeException(message, t); 
} 

或者換一個斷點在catch { }聲明檢查你在這個階段應用程序的狀態,但據我所知,這可能不適用於你所描述的情況。

(順便說一句,我建議你標記的「Java」添加到你的問題。這樣,它也將StackOverflow上的Java社區可見)

+0

由於不正是我想要的。注意到你的建議也是標籤 – ron