C# - Runtime error information

If an exception is thrown, the output contains the stack trace two times, but nothing else.

Little example. Suppose the code is:

static void B()
{
    var input = new int[1];
    var a = input[10];
}

static void Main(string[] args)
{
    B();
}

The output is:

Unhandled Exception:
at Player.B on line 95
at Player.Main on line 100
at Player.B on line 95
at Player.Main on line 100

Please include the full qualified name of the exception, and it’s message, so it could be more helpful, like this:

Unhandled System.OutOfRangeException: Index was outside the bounds of the array.
at Player.B on line 95
at Player.Main on line 100

The duplicate stack trace is also a bit annoying, but it’s not a showstopper bug.

Thank you very much!
adhie

1 Like

+1 this is tedious beyond words. You’re basically left to guess what has gone wrong.

static void Main(String[] args)
{
    try
    {
        // your code here
    }
    catch(Exception e)
    {
        Console.Error.WriteLine(e);
    }
}
2 Likes