我正在维护一些似乎不会停止在stop语句上的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
答案 0 :(得分:5)
我认为Stop只会为调试创建一个断点。
代码的执行将继续。
我认为在Return MyBase.Save中抛出异常。它被捕获在Catch块中,但它实际上被该块忽略,因为ex从未使用过。