Finding name of exception method

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

Is it possible to collect name of method, line, file etc in which exception
occurred? I have heard its possible using System.Diagnostics.StackTrace but
not sure how.

Many Thanks

Regards
 
Hi

Is it possible to collect name of method, line, file etc in which exception
occurred? I have heard its possible using System.Diagnostics.StackTrace but
not sure how.

Many Thanks

Regards

Handle exception in a try-catch block and call stacktrace property as
in the example:

/////////////////////////////////////

Try
Dim a As Integer = 0
Dim b As Integer = 0
Dim c As Integer = 0

a = a \ c
Catch ex As Exception
' View the line, file and method that exception was occured at.
MsgBox(ex.StackTrace)
End Try

/////////////////////////////////////


HTH,

Onur GÜZEL
 
Am 23.03.2010 10:46, schrieb John:
Is it possible to collect name of method, line, file etc in which exception
occurred? I have heard its possible using System.Diagnostics.StackTrace but
not sure how.

\\\
Dim CurrentStack As New StackTrace()
MsgBox("Current method: " & CurrentStack.GetFrame(0).GetMethod().Name)
MsgBox("Calling method: " & CurrentStack.GetFrame(1).GetMethod().Name)
MsgBox("Line number: " &
CStr(CurrentStack.GetFrame(0).GetFileLineNumber()))
///
 
Back
Top