Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
您现在的位置: Android教程網 >> Android系統教程 >  >> Android 技術 >> Android 開發 >> 進階開發

Log.wtf() 這個方法你用過嗎?

編輯:進階開發

從 Android 2.2(API Level 8)開始,Logcat 的日誌類別多了一個新方法:wtf()。平時我們會寫成 Log.wtf()。

在 android.util.Log 類別中,wtf 提供了三種多載版本,差別只在參數:

static int wtf(String tag, Throwable tr)
What a Terrible Failure: Report an exception that should never happen.

static int wtf(String tag, String msg)
What a Terrible Failure: Report a condition that should never happen.

static int wtf(String tag, String msg, Throwable tr)
What a Terrible Failure: Report an exception that should never happen.

顧名思義,這個方法是用來回報「本來根本不該發生」的例外狀況或狀態——也就是那種一旦出現就代表程式邏輯已經出錯的等級。它比一般 Log.e() 帶有更強的語意:不只是記錄錯誤,而是標示「這件事在正確的設計中不該存在」。

最後提醒:wtf() 是 2.2 SDK 才新增的方法,如果你的環境找不到它,請先檢查 SDK 版本。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved