Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我们可以只使用 finally 块而不添加 Try 和 Catch 块吗?
不,我们不可以。肯定是:
try {} catch {} finally {}
或者
try {} finally {}
该try块定义了后续finally应用的代码区域。您的建议只会相当于一些薄的语法糖,其中前面的整个代码块finally将隐式包装在try.
try
finally
该catch块是可选的。
catch