Results 1 to 7 of 7

Thread: Method to find the exact line of code that caused an error in VB.NET using Try Catch

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2020
    Posts
    70

    Method to find the exact line of code that caused an error in VB.NET using Try Catch

    When an error occurs while executing the project (in this case, dividing by zero), the message box displays the exception details, including the file path, procedure and line number where the error occurred, such as "Form1.vb:line 5".
    Code:
    Public Class Form1
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Try
                Dim d As Integer
                Dim c As Integer = d / 0
                MsgBox(c.ToString)
            Catch ex As Exception
                MsgBox(ex.toString)
            End Try
        End Sub
    End Class
    For the above code, Is there any code that can be placed in catch part so that message box should display the exact line of code that caused the error, i.e., "Dim c As Integer = d / 0" which would be helpful for logging spcific line of code where error occured for larger coding projects.

    I want to get the line of code along with line number details for easier Debugging.
    Last edited by IT_Researcher; Dec 5th, 2024 at 03:40 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width