尝试catch异常总是返回null [英] try catch exception always returns null
问题描述
我有问题了Android。我开发的设备和有问题的捕捉异常。我跑了一些code在AsyncTask的最后简化到:
I got problem with Android. I develop on device and have problem with catching exceptions. I'm running some code in AsyncTask and finally simplified it to:
try
{
if (true)
throw new Exception("ERROR");
}
catch (Exception e)
{
Log.e("e", "exception", e);
}
我的问题是,'E'变量总是空。不知道发生了什么实际。更重要的是它有时工作,但我不能说什么时候。我刚起床从电脑几分钟,回来的繁荣,它的工作原理。这样做的编码几分钟,这又是空......有对SO大约一年前,但没有人知回答一个问题。也许这时候会有人有一些想法。
My problem is that 'e' variable is always null. Not sure what's happening actually. What's more it sometimes works, but I can't say when. I just get up from computer for few minutes come back and boom, it works. Doing coding few minutes and again it's null... There was one question on SO about 1 year ago but noone known answer. Maybe this time someone will have some idea.
我觉得这有什么用的AsyncTask来做为它外面,我得到了异常正确逮住......仍然没有任何线索,为什么:(我发现它只是发生在debbuger相连。当我拿出电缆从设备,它实际上捕获和异常不为空了...
I think that it have something to do with AsyncTask as outside of it, I got exception catched properly... still don't have any clue why :( I found it only happens when debbuger is connected. When I take out cable from device it actually catches and exception isn't null anymore...
推荐答案
这是不可能有电子
与在该点空值。如果您正在调试使用Eclipse你的应用程序,它会显示在该点的 e.toString()
值和 e.toString()
将返回空
。
It's impossible to have e
with null value at that point. If you are debugging your app using Eclipse, it will show the e.toString()
value at that point and the e.toString()
is returning null
.
尝试其他的测试,使用这种code:
Try another test, using this code:
try {
if (true) {
throw new Exception("ERROR");
}
}
catch (Exception e) {
if (e == null) {
Log.e("e", "e is really null!!!");
}
else {
Log.e("e", "e is not null, toString is " + e + " and message is " + e.getMessage());
}
}
这篇关于尝试catch异常总是返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!