我想执行一堆抛出异常的命令,但我遇到程序正常执行的问题.
这是我的代码的基本大纲:
try
{
command1 //all three throw exceptions
command2
command3
}
catch (Exception e)
{
//log the exception in a txt file and continue onto the next command
}
Run Code Online (Sandbox Code Playgroud)
如果command1抛出异常,我如何让我的程序移动到command2?换句话说,如何返回try-block并从中断处继续执行?谢谢.
一旦进入catch块,就永远无法返回try块.您必须制作三个块才能继续执行.
try { command1(); }
catch (Exception e) { log(e); }
try { command2(); }
catch (Exception e) { log(e); }
try { command3(); }
catch (Exception e) { log(e); }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
204 次 |
| 最近记录: |