为什么使用最后尝试...抓住 [英] Why use Finally in Try ... Catch

查看:127
本文介绍了为什么使用最后尝试...抓住的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到最终 Try .. Catch 将始终执行后执行的任何部分尝试catch块。

I see that the Finally in Try .. Catch will always execute after any parts of the execution of the try catch block.

有没有什么不同,只是跳过最后部分,只是运行它,在尝试catch块?

Is it any different to just skip the Finally section and just run it after, outside the try catch block?

    Try
        'Do something
    Catch ex As Exception
        'Handle exception
    Finally
        'Do cleanup
    End Try



示例2,尝试...抓住...结束尝试...做最后的东西外面



Example 2, Try ... Catch ... End Try ... Do the finally stuff outside

    Try
        'Do something
    Catch ex As Exception
        'Handle exception
    End Try
    'Do cleanup


推荐答案

是的,它是不同的。最后总是运行(禁止程序崩溃)。如果函数退出try catch块的内部,或者try或catch中抛出另一个错误,finally将仍然执行。你不会得到这个功能不使用finally语句。

Yes, it is different. Finally will always run (barring program crash). If the function exits inside of the try catch block, or another error is thrown in either the try or the catch, the finally will still execute. You won't get that functionality not using the finally statement.

这篇关于为什么使用最后尝试...抓住的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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