Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 820925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:33:25+00:00 2026-05-15T02:33:25+00:00

I am trying to build an error handler for my desktop application. The code

  • 0

I am trying to build an error handler for my desktop application. The code Is in the class ZipCM.ErrorManager listed below.

What I am finding is that the outputted file is not giving me the correct info for the StackTrace.

Here is how I am trying to use it:

Try
     '... Some stuff here!

     Catch ex As Exception
            Dim objErr As New ZipCM.ErrorManager
            objErr.Except = ex
            objErr.Stack = New System.Diagnostics.StackTrace(True)
            objErr.Location = "Form: SelectSite (btn_SelectSite_Click)"
            objErr.ParseError()
            objErr = Nothing
        End Try

Here is the class:

    Imports System.IO

Namespace ZipCM

    Public Class ErrorManager

        Public Except As Exception
        Public Location As String
        Public Stack As System.Diagnostics.StackTrace

        Public Sub ParseError()
            Dim objFile As New StreamWriter(Common.BasePath & "error_" & FormatDateTime(DateTime.Today, DateFormat.ShortDate).ToString().Replace("\", "").Replace("/", "") & ".log", True)
            With objFile
                .WriteLine("-------------------------------------------------")
                .WriteLine("-------------------------------------------------")
                .WriteLine("An Error Occured At: " & DateTime.Now)
                .WriteLine("-------------------------------------------------")
                .WriteLine("LOCATION:")
                .WriteLine(Location)
                .WriteLine("-------------------------------------------------")
                .WriteLine("FILENAME:")
                .WriteLine(Stack.GetFrame(0).GetFileName())
                .WriteLine("-------------------------------------------------")
                .WriteLine("LINE NUMBER:")
                .WriteLine(Stack.GetFrame(0).GetFileLineNumber())
                .WriteLine("-------------------------------------------------")
                .WriteLine("SOURCE:")
                .WriteLine(Except.Source)
                .WriteLine("-------------------------------------------------")
                .WriteLine("MESSAGE:")
                .WriteLine(Except.Message)
                .WriteLine("-------------------------------------------------")
                .WriteLine("DATA:")
                .WriteLine(Except.Data.ToString())
            End With
            objFile.Close()
            objFile = Nothing
        End Sub

    End Class

End Namespace

What is happenning is the .GetFileLineNumber() is getting the line number from objErr.Stack = New System.Diagnostics.StackTrace(True) inside my Try..Catch block. In fact, it’s the exact line number that is on.

Any thoughts of what is going on here, and how I can catch the real line number the error is occuring on?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:33:26+00:00Added an answer on May 15, 2026 at 2:33 am

    Edit: Changed the code to account for the Exception.StackTrace being a string rather than a real StackTrace

    You’re creating a new StackTrace, so then it will be for the line you’re declaring it on, if you want the line number of the original exception, use the stack trace in Exception.StackTrace.

    I think you’re being a little confused, I can’t see why you create the new StackTrace at all?

    Edit: Added more bits to the answer here since easier to see the syntax than in a comment

    Currently you have the line

     objErr.Stack = New System.Diagnostics.StackTrace(True)
    

    Which means that you’re creating a whole new stacktrace, starting when you’re creating it.

    Instead change that line to:

    objErr.Stack = New System.Diagnostics.StackTrace(ex, True)
    

    Which will have the stacktrace from when the error actually happened.

    Edit: Added complete sample:

    Private Sub a1()
        Try
            a2()
        Catch ex As Exception
            Dim st As New StackTrace(True)
            Debug.WriteLine(String.Format("ST after exception, will give line number for where st was created. Line No: {0}", st.GetFrame(0).GetFileLineNumber()))
    
            st = New StackTrace(ex, True)
            Debug.WriteLine(String.Format("ST after exception using exception info, will give line number for where exception was created. Line No: {0}", st.GetFrame(0).GetFileLineNumber()))
        End Try
    End Sub
    
    Private Sub a2()
        Dim st As New StackTrace(True)
        Debug.WriteLine(String.Format("ST before exception, will give line number for where st was created. Line No: {0}", st.GetFrame(0).GetFileLineNumber()))
        Dim b As Integer = 0
        Dim a As Integer = 1 / b
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is not pretty but it works: rm -R $(ls… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer Yes. Override the base1 and base2 methods in Derived to… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer No, you can't. Unfortunately, UIEvent doesn't expose any public way… May 16, 2026 at 12:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.