返回在catch块语句 [英] Return statements in catch blocks
问题描述
我已经看到了一些开发商利用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屋!