如果Try没有Catch,会发生什么 [英] What happens if Try doesn't have Catch

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

问题描述

嗨朋友们,

try {} finally {}语句没有捕获的结果是什么?

例如:

Hi friends,
What is the result of try{}finally{} statement without catch ??
Eg:

try
{
//some code
}
finally
{
//some code
}





不会抛出异常吗?



Won't it throw an Exception ??

推荐答案

您仍然可以使用此构造来清理可能在方法中使用的资源。

当然,错误处理必须在其他地方完成。
You can still use this construct to clean up resources that you might be using in a method.
Of course, error handling will have to be done somewhere else.


尝试 Catch 是否(如他们的名字所示)捕捉到某些东西(异常)。如果你不想抓住它,你为什么要使用试试根本?



最后将在尝试OR catch语句后执行,但是使用尝试而不用 catch 没有意义。这不会给你任何错误



问候..
Try and Catch is there(as their name suggest) to catch something(exception).If you don't want to catch it, why are you using try at all?

finally will get executed after try OR catch statement,but to use try without catch makes zero sense. That wont give you any error.

Regards..


这篇关于如果Try没有Catch,会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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