我正在维护一些似乎不会在停止语句上停止的 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