Domanda

I've recently inherited a C# (.NET 4.0) project at work. The project is 400k+ lines of code and uses many large, large try/catch blocks that catch any Exception. Occasionally, the application throws an IndexOutOfRangeException, and my boss has asked me to attempt to find an easy way to uncover the name of the array that threw the exception. (Such large try/catch blocks can contain many arrays.) I know that I can use the FirstChanceException event to trigger code to execute when the IndexOutOfRangeException is thrown. For example:

class ExceptionTest
{
    public static void Main()
    {
        AppDomain.CurrentDomain.FirstChanceException
+= new EventHandler<FirstChanceExceptionEventArgs>(CurrentDomain_FirstChanceException);
        int[] arr = new int[0];
        arr[0] = 0;
        Console.Read();
    }

    static void CurrentDomain_FirstChanceException(object sender, 
FirstChanceExceptionEventArgs e)
    {
        if (e.Exception.GetType() == typeof(IndexOutOfRangeException))
        {
            Console.WriteLine(e.Exception.StackTrace);
        }
    }
}

Unfortunately, I can't seem to find the problematic array's name in this manner, but combing through 400k+ lines of code isn't an option.

I personally don't understand the point of this task, but I would appreciate any help. Is this even possible?

EDIT: 5. August 2014

I should clarify: it's very easy to find the problematic arrays when debugging in VS. The point of this task is to discover which arrays throw exceptions when the release build of the program is being used by our clients. The program uses a set of log files, but these files only indicate the type of exception that is thrown - not the array name or line number.

È stato utile?

Soluzione 2

I have discovered with much thought, research, and experimentation that what is described is not possible. Yes, I could obtain in the line number, but unfortunately, there are so many different versions of the compiled application distributed that the code is very dynamic and a line number would be meaningless.

Altri suggerimenti

use this code

try
{
    //large number of arrays in you code like
    int[] arr1;
    int[] arr2;
    //these type of codes and declerations
}
catch(Exception e)
{
    Console.WriteLine(e.Message + "  " + e.StackTrace);
}

Now this StackTrace will show you on which line number, there is the error in your code

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top