1

在以下代码中,Inner_A(x) 中引发了异常。如何在堆栈跟踪中显示 x 的值,因为堆栈跟踪如下所示:

at Default2.Inner_A(String x) in C:\test1\Default2.aspx.vb:line 25
at Default2.Page_Load(Object sender, EventArgs e) in C:\test1\Default2.aspx.vb:line 12






Dim strErrorMesssage As String

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Try
        Dim x As String = "testvar"

        Inner_A(x)
    Catch ex As Exception

        strErrorMesssage &= DirectCast(ex, System.ApplicationException).StackTrace.ToString()

    End Try


End Sub


Private Function Inner_A(ByVal x As String) As String

    Throw New ApplicationException("Exception Occured caused in INNER_A ")

    Return " Function Inner_A"

End Function
4

1 回答 1

1

您不能修改堆栈跟踪,但可以在错误消息中包含变量的值:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim x As String
    Try
        x = "testvar"

        Inner_A(x)
    Catch ex As Exception
        strErrorMesssage &= "X = " & x & Environment.NewLine & DirectCast(ex, System.ApplicationException).StackTrace.ToString()
    End Try
End Sub
于 2013-01-19T04:26:27.050 回答