Java Try Catch Finally blocks without Catch

后端 未结 11 801
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 20:38

I\'m reviewing some new code. The program has a try and a finally block only. Since the catch block is excluded, how does the try block work if it encounters an exception

11条回答
  •  旧时难觅i
    2020-11-28 21:24

    If any of the code in the try block can throw a checked exception, it has to appear in the throws clause of the method signature. If an unchecked exception is thrown, it's bubbled out of the method.

    The finally block is always executed, whether an exception is thrown or not.

提交回复
热议问题