Results 1 to 9 of 9

Thread: [RESOLVED] Problem with getting line number on errors

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Posts
    84

    Resolved [RESOLVED] Problem with getting line number on errors

    Afternoon,

    I have recently found i'm getting a few unhandled errors that I don't know the cause of so I set about trapping those and recording the information.

    Using a few different websites I have put together the following code in my Program.cs file:

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows.Forms;
    using System.Threading;
    using System.Diagnostics;
    
    namespace WindowsFormsApplication1
    {
        static class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
    
            static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
            {
                DialogResult result = DialogResult.Abort;
                try
                {
                    StackTrace trace = new StackTrace(true);
    
                    StackFrame frame = trace.GetFrame(0);
    
                    result = MessageBox.Show("Whoops! Please contact the developer with the following information:\n\n" +
                        "Message: " + e.Exception.Message + "\n\n" +
                        "Source: " + e.Exception.Source + "\n\n" +
                        "Method: " + frame.GetMethod().Name + "\n\n" +
                        "Filename: " + frame.GetFileName() + "\n\n" +
                        "Line: " + frame.GetFileLineNumber() + "\n\n" +
                        "Column:" + frame.GetFileColumnNumber() + "\n\n" +
                        "Data: " + e.Exception.Data + "\n\n" +
                        "Helplink: " + e.Exception.HelpLink + "\n\n" +
                        "InnerException: " + e.Exception.InnerException + "\n\n" +
                        "Targetsite: " + e.Exception.TargetSite + "\n\n" +
                        "Stack Trace:\n" + e.Exception.StackTrace, "Application Error",
                      MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop);
                }
                finally
                {
                    if (result == DialogResult.Abort)
                    {
                        Application.Exit();
                    }
                }
    
            }
    
    
        }
    }
    Whilst most of this works, i'm not getting anything back to tell me the line and column number, instead they are just reported as 0's.

    All I need is it to tell me the error type, file it happened in, line and colum number so if someone can point me in the right direction or tell me what i've done wrong i'd greatly appreciate it.

    I am using Visual C# 2010 Express.
    Last edited by Madcat1981; Jan 6th, 2016 at 09:57 AM.

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