将try catch最终阻塞在另一个finally块中 [英] Putting try catch finally block inside another finally block

查看:164
本文介绍了将try catch最终阻塞在另一个finally块中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 try{
  }catch(){}
  finally{
     try{
      }catch(){ }
     fianlly{ }
  }

拥有上述代码是否合适?

Is it good to have the code like above?

推荐答案

是的,你可以这样做。

实际上,你甚至需要在处理你想要正确关闭的流时要做到这一点:

Actually, you are even required to do it when dealing with streams you want to close properly:

InputStream in = /* ... */;
try {
} catch (...) {
} finally {
    try {
        in.close();
    } catch (...) {
    } finally {
    }
}

我认为这不是一个不好的做法

I don't see any case in which this would be a bad practice

这篇关于将try catch最终阻塞在另一个finally块中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆