1

我正在调试 ASP.net Web 应用程序项目中的一些代码。

我有一个嵌套在 Try/Catch 块中的 If/Else 语句。每当在 If 块中发生错误时,它不会立即跳入 Catch 块,而是落入 Else 块。

我已经反复通过代码来见证这种情况的发生。当我在 if 块中抛出异常时,我希望逻辑会流入 catch 块,我永远不会期望看到 if 块被命中,然后 else 块被命中,这似乎完全违背了if/else 逻辑。

这是有问题的代码:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    LoadDocument()
End Sub

Private Sub LoadDocument()
    Dim taDocuments As New SecureTableAdapters.IndividualDocumentsTableAdapter
    Dim dtDocuments As New Secure.IndividualDocumentsDataTable
    Dim iDocumentID As Integer = CInt(Request.QueryString("iDocumentID"))
    Dim sFileName As String
    Dim isMac As Boolean = clsApplication.isMac(Request.Browser.Platform)
    Dim bDownloaded As Boolean = False

    Try
        If taDocuments.FillBy_IndividualDocumentID(dtDocuments, iDocumentID) > 0 Then
            Dim oRow As Secure.IndividualDocumentsRow = dtDocuments.Rows(0)
            sFileName = "Statement-" & oRow.sFileNumber & ".pdf"

            If oRow.sDocumentName.ToUpper.Contains("LEDES") Or oRow.sDocumentName.ToUpper.Contains("TEXT") Then
                sFileName = sFileName.Replace("pdf", "txt")
            End If

            Dim b As Byte() = Nothing

            If oRow.IsbExtractedNull = False AndAlso oRow.bExtracted Then

                Dim sHost As String = "206.220.201.175"
                Dim sPath As String = String.Format("/Legacy/{0}/{1}/{2}.pdf", oRow.iFirmID.ToString, "Individuals", oRow.iIndividualDocumentID.ToString)
                b = DownloadDocument(sHost, sPath)

                If b Is Nothing Then
                    'When this line is hit, logic jumps to the else block with the comment below
                    Throw New Exception("FTP Download Failed")
                Else
                    bDownloaded = True
                End If
            Else
                bDownloaded = False
            End If

            If bDownloaded = False Then
                b = getImage(iDocumentID, "oPDF", "iIndividualDocumentID", "tblIndividualDocuments")
                If b Is Nothing Then
                    Throw New Exception
                End If
            End If

            If isMac Then
                Response.ContentType = "application/x-macbinary"
            Else
                Response.ContentType = "application/octet-stream"
            End If

            Response.Expires = 0
            Response.AddHeader("Content-Disposition", "attachment; filename=""" & sFileName & """")
            Response.BinaryWrite(b)
        Else
            '--->When the exception occurs, logic jumps to this else block
            Throw New Exception
        End If
    Catch ex As Exception
        Response.Write("Sorry, that statement could not be located. Please try again, or call us at xxx.xxx.xxxx for further information.")
        clsApplication.EmailError("An error occurred downloading a statement: " & vbCrLf & ex.Source & vbCrLf & ex.Message & vbCrLf & ex.StackTrace)

    End Try

End Sub

这怎么可能?

4

3 回答 3

2

听起来您正在使用优化仍然打开的调试器。这可能会导致步骤跟踪以看似不合逻辑甚至不可能的方式进行操作。这是因为在优化器移动代码和变量并合并不同的语句之后,源代码行与可执行指令之间不再存在简单或直接的关系。

于 2013-10-02T22:36:10.553 回答
1

听起来您正在调试的代码可能与正在执行的代码不同步。尝试重建整个解决方案。

于 2013-10-02T20:00:41.293 回答
0

我想你可能弄错了:

在简单的 vb .net winforms 程序中尝试以下操作。

Public Class Form1

   Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
      Try
         Dim doIt As Boolean = True
         If doIt Then
            Throw New Exception("throwing that stuff")
         Else
            MsgBox("in here - how did that happen?")

         End If
      Catch ex As Exception
         MsgBox(String.Format("That makes sense.  Exception is: {0}", ex))
      End Try


   End Sub
End Class
于 2013-10-02T19:42:19.077 回答