Click here to Skip to main content
15,881,561 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Whats wrong here in the Code I am getting this error at the indicated line

VB
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

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.

VB
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
 
Share this answer
 
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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900