我的 Android 应用程序中有以下代码:
/**
* Returns a single customer object based on UUID. */
public static Customer getCustomer(UUID id)
{
try
{
Cursor cursor = CustomApp.data.db.query("Customer", customerCols,
"CustomerId='" + id.toString() + "'", null, null, null, null);
if (cursor != null)
cursor.moveToFirst();
Customer cust = new Customer(id);
// Unrelated code here
if (!cursor.isNull(23))
cust.isDeceased = (cursor.getInt(23) > 0); // EXCEPTION
// More unrelated code here
return cust;
}
catch (Exception ex)
{
ex.printStackTrace(); // This line gets skipped
return null; // Code jumps to here
}
}
我正在尝试调试它。 cust.isDeceased = (cursor.getInt(23) > 0);
行出现异常(为什么我收到异常完全是另一个问题)。当代码到达该行时,它会跳转到 catch
部分。我在 ex.printStackTrace();
行上放置了一个断点,但代码完全跳过了这一行。它只是直接跳转到 return null;
行,并且堆栈跟踪从不打印。因此,调试代码变得非常困难,因为我必须猜测出了什么问题。 (如果您发现该代码有问题,请告诉我,但这不是这个问题的目的)。
我很抱歉缺少我提供的信息/代码,但由于我确实不知道为什么会发生这种情况,所以我不知道什么是相关的,什么是不相关的。有人遇到过这个问题吗?
最佳答案
Log.e("标签", "错误", ex);尝试这个而不是 ex.printStackTrace(); 也尝试重新启动 eclipse。
关于java - 代码不打印堆栈跟踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18056860/