返回在catch块语句 [英] Return statements in catch blocks

查看:153
本文介绍了返回在catch块语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了一些开发商利用return语句的catch块。为什么/时,这会是一个有用的技术采用?

I have seen some developers use the return statement in a catch block. Why/when would this be a useful technique to employ?

编辑:其实我刚才看到使用return关键字

I actually just saw the return keyword being used.

感谢

推荐答案

公共无效函数() {

try 
{ 
    //some code here
}
catch
{ 
    return;
}

}

当回报;被击中,执行流跳出功能。这只能在空的方法来实现。

when return; is hit, the execution flow jumps out of the function. This can only be done on void methods.

编辑:你这样做,如果你不想执行该功能的其余部分。例如,如果你正在做文件IO与读取错误发生,你不想要执行code,因为你没有它处理处理数据在该文件中。

you do this if you dont want to execute the rest of the function. For example if you are doing file IO and a read error happens, you dont want to execute code that handles processing the data in that file since you dont have it.

这篇关于返回在catch块语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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