Is a finally block without a catch block a java anti-pattern?

前端 未结 12 675
鱼传尺愫
鱼传尺愫 2020-12-05 12:35

I just had a pretty painful troubleshooting experience in troubleshooting some code that looked like this:

try {
   doSomeStuff()
   doMore()
} finally {
            


        
12条回答
  •  醉酒成梦
    2020-12-05 13:15

    Not at all.

    What's wrong is the code inside the finally.

    Remember that finally will always get executed, and is just risky ( as you have just witnessed ) to put something that may throw an exception there.

提交回复
热议问题