Reputation: 9555
In the following code an exception is thrown in Inner_A(x). How do I show in the stack trace what the value of x was as the stack trace looks like this:
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
Upvotes: 1
Views: 180
Reputation: 44971
You can't modify the stack trace, but you can include the value of the variable in your error message:
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
Upvotes: 1