1
我正在維護一些似乎停止停止聲明的VB代碼。爲什麼我的vb代碼停止在停止語句上?
當我在某些條件下運行程序時,此代碼從最後一行代碼中引發System.Exception(「Timed out」)。
但是,如果你逐行通過代碼,它似乎永遠不會碰到這個聲明。首先它會嘗試返回MyBase.Save。如果它不能,那麼它會打停止聲明並停止。
但似乎程序只是跳過停止聲明。
如何調試此代碼?具體地講,它是如何跳過停止語句去聲明拋出新的System.Exception(「超時」)
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
+1 - 請參閱http://msdn.microsoft.com/en-us/library/8a094y2f%28v=vs.80%29.aspx – hatchet 2012-07-12 15:43:06
@hatchet您評論中的鏈接說,如果不進行調試,停止操作像End。它終止執行。所以這個答案是錯誤的。 – MarkJ 2012-07-12 19:20:59
@MarkJ - 這是一個很好的觀察。我想這取決於OP「在某些條件下運行程序時」的含義。 – hatchet 2012-07-12 20:02:53