when in a try..catch.., is it possible to capture the line number that the code is at when the catch happens? I'd like to do so for logging purposes.
Printable View
when in a try..catch.., is it possible to capture the line number that the code is at when the catch happens? I'd like to do so for logging purposes.
exception.getobjectdata is supposed to return serializable data about the exception, but I don't know much about it. You could parse the exception.tostring text for the text starting with "line no...."
I'm not sure if it would help in an exe; since most comments are stripped out, I don't know if the line numbers there would necessarily match those in the IDE.
exception.targetsite.tostring will give you the sub that threw the exception.
Example
VB Code:
Try 'Code Here Catch ex As Exception Dim strErrMsg As String = ex.Message.ToString() Dim strTrace As String = ex.StackTrace.ToString() 'Call your logging function Call LogError(strErrMsg, strTrace) End Try
You could also look into using the stack trace class:
http://msdn.microsoft.com/library/de...classtopic.asp
that's exactly what I was looking for! thanks fellas! :)