它是合法的,并可以访问在返回值finally块? [英] Is it legal and possible to access the return value in a finally block?

查看:126
本文介绍了它是合法的,并可以访问在返回值finally块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在离开前一个函数,根据返回code和变量的函数来设置一个usererror字符串。

I wish to set a usererror string before leaving a function, depending on the return code and variable in the function.

我目前有:

Dim RetVal as RetType

try
...
if ... then
    RetVal = RetType.FailedParse
    end try
endif
...

finally
    select case RetVal
        case ...
            UserStr = ...
    end select
end try

return RetVal

是否可以使用回RetType.FailedParse,然后访问该在finally块?

Is it possible to use return RetType.FailedParse, then access this in the finally block?

推荐答案

做这在C#是在方法的开始来声明一个变量的唯一真正的方式来保存值 - 即

The only real way of doing this in C# would be to declare a variable at the start of the method to hold the value - i.e.

SomeType result = default(SomeType); // for "definite assignment"
try {
   // ...
   return result;
}
finally {
    // inspect "result"
}

在VB中,你的也许的能够直接访问的结果 - 因为IIRC它有点就像上面(与方法名称中的结果)反正。警告:我的真的不是一个VB的人......

In VB, you might be able to access the result directly - since IIRC it kinda works like the above (with the method name as "result") anyway. Caveat: I'm really not a VB person...

这篇关于它是合法的,并可以访问在返回值finally块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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