您可以从try块中返回,但请记住,finally方法中的代码将在从方法返回之前执行.例如,MessageBox.Show(test().ToString());使用下面的方法调用将导致出现两个消息框(第一个显示"3",第二个显示"1").
Run Code Online (Sandbox Code Playgroud)int test() { try { return 1; throw new Exception(); } catch (Exception e) { return 2; } finally { MessageBox.Show("3"); } }
| 归档时间: |
|
| 查看次数: |
1022 次 |
| 最近记录: |