Click here to Skip to main content
14,329,915 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,
Whats wrong here in the Code I am getting this error at the indicated line

Public Shared Sub LogInfo(ByVal ex As Exception)
    Try
        'Writes error information to the log file including name of the file, 
        'line number & error message description

        ' error happens here
        Dim trace As Diagnostics.StackTrace = New Diagnostics.StackTrace(ex, True)

        Dim fileNames As String = trace.GetFrame((trace.FrameCount - 1)).GetFileName()
        Dim lineNumber As Int32 = trace.GetFrame((trace.FrameCount - 1)).GetFileLineNumber()

        Info("Error In" + fileNames + "Line Number" + lineNumber.ToString() + "Error Message" + ex.Message)
    Catch
        Throw
    End Try
End Sub
Posted
Updated 24-Feb-12 2:13am
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

Why don't you use the StackTrace property from the exception parameter? there's also no need for the try/catch block in this instance.

Public Shared Sub LogInfo(ByVal ex As Exception)
    Dim fileNames As String = "UNKNOWN"
    Dim lineNumber As Int32 = -1
    If ex IsNot Nothing then
        fileNames = ex.StackTrace.GetFrame((ex.StackTrace.FrameCount - 1)).GetFileName()
        lineNumber = ex.StackTrace.GetFrame((ex.StackTrace.FrameCount - 1)).GetFileLineNumber()
    End If
    Info("Error In" + fileNames + "Line Number" + lineNumber.ToString() + "Error Message" + ex.Message)
End Sub
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

in fact this line getting me into trouble
piconfile.Items.FindByValue(objAdminDataLayer.sqlDR("piconfile")).Selected = True

then what I do
I just add another line
If Not piconfile.Items.FindByValue(objAdminDataLayer.sqlDR("piconfile")) Is Nothing Then
piconfile.Items.FindByValue(objAdminDataLayer.sqlDR("piconfile")).Selected = True

and Now that exception is occurred.
Thank You.
Regards
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100