返回在catch块语句语句、catch

2023-09-03 17:26:26 作者:空山梦

我已经看到了一些开发商利用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.