这个Catch语句是什么意思? [英] What is the point of this Catch statement?

查看:120
本文介绍了这个Catch语句是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在旧版代码中看到了这一点。什么,如果有的话,是一个单一的投掷的目的在一个抓住?

I seen this in legacy code. What, if any, is the purpose of a single Throw within a Catch?

       Try
           'Some Oracle access statement
       Catch err As OracleClient.OracleException
            Throw
       Finally
          'Do something
       End Try

结果是同样的原始错误没有被抓住?您是否使用Throw语句w / o参数来重新抛出原始错误,通常在执行某些操作后首先执行?

Is the outcome the same as if the original error was not caught? Would you use a Throw statement w/o parameters to re-throw the original error, typically after performing some action first?

推荐答案

它看起来像是用来鼓动错误。尽管在这种情况下,通常会将更多的内容放在catch语句中,而不仅仅是抛出(即记录,警报等),它允许使用finally语句进行一些清理,然后将错误冒泡到下一级。没有try / catch这个清理代码将如何写在这个范围?正如有人提到的那样,throw语法(没有ex)是保留堆栈跟踪。

It looks like it is being used to bubble the error up. While one would normally put more in the catch statement than just throw (i.e. logging, alerts, etc.) in this case it is allowing a finally statement to be used to do some cleanup then bubbling the error up to the next level. Without the try/catch how would this cleanup code be written at this scope? As someone mentioned already the throw syntax (without ex) is preserving the stack trace.

这篇关于这个Catch语句是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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