2013-01-19 163 views
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 

回答

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