简体   繁体   English

Java throw e在Android上变为null

[英]Java throw e becomes null on Android

I have the following: 我有以下内容:

     try {
        response.statusCode = urlConnection.getResponseCode();    
     } catch(IOException e) {
        throw e;
     }

I look at the debugger and e = UnknownHostException 我查看调试器和e = UnknownHostException

After the throw I have: 投掷后我有:

    try {
        NetworkResponse response = NetworkHelper.getByURL(url);
     } catch(Exception e) {   <------- IT LANDS HERE, BUT e=null
        ExceptionHelper.announce(e);        
        throw e;
    }

So after the throw my catch block gets the exception but it's null. 所以在抛出之后我的catch块获取异常,但它是null。 The debugger shows e=null. 调试器显示e = null。

I have no idea why this would happen. 我不知道为什么会这样。

I don't even see the point of catching the exception if you just immediately rethrow it. 如果您只是立即重新抛出它,我甚至没有看到捕获异常的重点。 Add a throws IOException to that method and let the other catch handle it. 向该方法添加一个throws IOException ,让另一个catch处理它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM