Home > Enterprise >  Asp.net Server.GetLastError don't have line number
Asp.net Server.GetLastError don't have line number

Time:04-20

when i look in the stack trace of a try/catch, i have the row of my code that throw exception. if i don't manage try/catch to redirect to a custom page and get my last exception with Server.GetLastError i have a different stack trace. for example: with try catch i have my line reference enter image description here

without try catch, on my custom page nothing enter image description here

i tried also

Dim ex As Exception = Server.GetLastError.GetBaseException
Dim trace As New Diagnostics.StackTrace(ex, True)

as suggested in an other post, but is not working. i wrong something?

CodePudding user response:

this is how i solved:

Dim ex As Exception = Server.GetLastError()
            Dim StackTraces As New Diagnostics.StackTrace(ex.InnerException, True)
            Dim StackFrame = Nothing

            For Each StackFrame In StackTraces.GetFrames()
                If (StackFrame.GetFileColumnNumber() > 0) Then
                    Exit For
                End If
            Next
  • Related