Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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 24-Feb-12 3:08am
Edited 24-Feb-12 3:13am
v2
Rate this: bad
good
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
  Permalink  
Rate this: bad
good
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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 406
1 Marcin Kozub 225
2 Sergey Alexandrovich Kryukov 205
3 /\jmot 175
4 Shweta N Mishra 161
0 OriginalGriff 8,289
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,624
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 24 Feb 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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