【问题标题】:why doesn't my vb code stop on a stop statement?为什么我的 vb 代码没有在 stop 语句上停止?
【发布时间】:2012-07-12 09:46:42
【问题描述】:

我正在维护一些似乎不会在停止语句上停止的 VB 代码。

当我在特定条件下运行程序时,此代码从最后一行代码抛出 System.Exception("Timed out")。

但是,如果您逐行查看代码,似乎它永远无法达到此语句。首先它尝试返回 MyBase.Save。如果不能,那么它会点击 stop 语句并停止。

但似乎程序只是跳过了停止语句。

如何调试此代码?具体来说,它如何跳过停止语句到达语句 Throw New System.Exception("Timed out")

Public Overrides Function Save() As Uber

    If IsDeleted AndAlso Not CanDeleteObject() Then
        Throw New System.Security.SecurityException("User is not authorized to remove a Uber")
    ElseIf IsNew AndAlso Not CanAddObject() Then
        Throw New System.Security.SecurityException("User is not authorized to add a Uber")
    ElseIf Not IsNew AndAlso Not CanEditObject() Then
        Throw New System.Security.SecurityException("User is not authorized to update a Uber")
    End If

    Try
        Return MyBase.Save
    Catch ex As Exception

        Stop   //why is the code not stopping here?
    End Try

    Throw New System.Exception("Timed out")  //this line executes, but I don't see how the code gets there

End Function

【问题讨论】:

    标签: .net vb.net


    【解决方案1】:

    我认为 Stop 只会为调试创建一个断点。

    代码的执行将继续。

    我认为 Return MyBase.Save 中引发了异常。它被 Catch 块捕获,但实际上被该块忽略,因为 ex 从未使用过。

    【讨论】:

    • @hatchet 您评论中的链接说,当不调试时,Stop 就像 End 一样。它终止执行。所以这个答案是错误的。
    • @MarkJ - 这是一个很好的观察。我想这取决于“当我在特定条件下运行程序时”的 OP 含义。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-13
    • 2011-04-06
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多