哪一个更倾向于抛出错误?(Which one is more tend to throw error?)

编程入门 行业动态 更新时间:2024-10-23 10:24:36
哪一个更倾向于抛出错误?(Which one is more tend to throw error?)

我正在审查一个应用程序,我想知道哪一个更容易出错?

Public Function ToBool(ByVal vsValue As String) As Boolean If IsNothing(vsValue) OrElse vsValue = "" Then Return False End If If UCase(vsValue) = "TRUE" Or vsValue = "1" Or UCase(vsValue) = "Y" Or UCase(vsValue) = "YES" Or UCase(vsValue) = "T" Then Return True Else Return False End If End Function

要么

Public Function ToBool(ByVal vsValue As String) As Boolean If IsNothing(vsValue) OrElse vsValue = "" Then Return False ElseIf UCase(vsValue) = "TRUE" Or vsValue = "1" Or UCase(vsValue) = "Y" Or UCase(vsValue) = "YES" Or UCase(vsValue) = "T" Then Return True Else Return False End If End Function

I am reviewing an application and I am wondering which one is more error-prone?

Public Function ToBool(ByVal vsValue As String) As Boolean If IsNothing(vsValue) OrElse vsValue = "" Then Return False End If If UCase(vsValue) = "TRUE" Or vsValue = "1" Or UCase(vsValue) = "Y" Or UCase(vsValue) = "YES" Or UCase(vsValue) = "T" Then Return True Else Return False End If End Function

or

Public Function ToBool(ByVal vsValue As String) As Boolean If IsNothing(vsValue) OrElse vsValue = "" Then Return False ElseIf UCase(vsValue) = "TRUE" Or vsValue = "1" Or UCase(vsValue) = "Y" Or UCase(vsValue) = "YES" Or UCase(vsValue) = "T" Then Return True Else Return False End If End Function

最满意答案

由于两个代码示例在语义上是相同的,因此哪个更容易出错是没有区别的。 如果代码进入第一个If块的主体,那么在两种情况下它都将退出该函数。 如果它没有进入第一个If块的主体,则执行的代码也是相同的。

There is no difference as to which one is more error prone, as the two code examples are semantically identical. If the code enters the body of the first If block, then in both cases it will exit the function. The code that executes if it does not enter the body of the first If block is also identical.

更多推荐

本文发布于:2023-07-26 00:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1268340.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:抛出   倾向于   错误   error   throw

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!