Java Try Catch Finally块没有Catch [英] Java Try Catch Finally blocks without Catch

查看:375
本文介绍了Java Try Catch Finally块没有Catch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在审核一些新代码。该程序只有一个try和一个finally块。由于catch块被排除在外,如果遇到异常或任何可抛出的东西,try块如何工作?它是直接转到finally块吗?

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 or anything throwable? Does it just go directly to the finally block?

推荐答案

如果try块中的任何代码都抛出一个已检查的异常,它必须出现在方法签名的throws子句中。如果抛出未经检查的异常,则会冒出该方法。

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.

无论是否抛出异常,都会始终执行finally块。

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

这篇关于Java Try Catch Finally块没有Catch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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