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 に答える