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

前端 未结 12 649
鱼传尺愫
鱼传尺愫 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:32

    I think that try with no catch is anti-pattern. Using try/catch to handle exceptional conditions (file IO errors, socket timeout, etc) is not an anti-pattern.

    If you're using try/finally for cleanup, consider a using block instead.

提交回复
热议问题