我有一个像这样的代码片段:
Log.i(tmpTag, "B4 URL CHANGE: URL in response = " + responseURL + ".\nLast URL = " + mLastUrl); //SHOWN IN LOGCAT
if (m_CurrentEventName.contentEquals("forgotpassword")) {
mLastUrl = responseURL.replace("../../../", "");
} else if (m_CurrentEventName.contentEquals("tskstdlogin") && responseURL.indexOf("changepassword") != -1) {
mLastUrl = responseURL.replace("../../../", "");
} else {
mLastUrl = responseURL;
}
Log.i(tmpTag, "AFTER URL CHANGE: URL in response = " + responseURL + "\nLast URL = " + mLastUrl); //NOT SHOWN IN LOGCAT
我期待两个日志语句,但只有第一个显示在LogCat中,如下所示:
08-27 09:39:06.867: I/bindDataTask(1994): B4 URL LOOP: URL in response = "some internal url".
08-27 09:39:06.867: I/bindDataTask(1994): Last URL = "some internal url".
知道为什么会这样吗?
答案 0 :(得分:1)
除了标记和优先级之外,Logcat消息还包含许多元数据字段。你的第一个日志行被执行所以它被打印但其他日志消息没有被打印,因为发生了一些异常,你的程序控制去了try-catch块的catch部分......
下面...
try{
Log.i(tmpTag, "B4 URL CHANGE: URL in response = " + responseURL + ".\nLast URL = " + mLastUrl); //SHOWN IN LOGCAT
...
...
// Exception occured..GOTO catch block
..
Log.i(tmpTag, "AFTER URL CHANGE: URL in response = " + responseURL + "\nLast URL = " + mLastUrl); //NOT SHOWN IN LOGCAT
.....
}catch(Exception e){
Log.e("Exception here...",e.toString());
}