In an application one should always try their best to ensure code is fully tested, and is written in such a way that malformed input or actions are handled gracefully.
We are only human though and mistakes creep in, in a last ditch effort to improve the user-experience instead of unceremoniously crashing to the desktop it is common to catch unhanded exceptions, throw a message to the user and record some fault information.
Usually a PDB is not distributed with the finished program and as such a system trace will not contain line numbers which can make it difficult to locate the offending line that threw the error.
Take the following example program (a .net console app for simplicity)
using System;
namespace ExceptionTest
{
class Program
{
static void Main(string[] args)
{
// Just in case we forget to catch something properly.
System.AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper;
Console.WriteLine(DoStuff(10));
Console.ReadKey();
}
static int DoStuff(int parameter)
{
int[] data = { 1, 2, 3, 4, 5, 6 };
int value = data[parameter]; // Improperly checked code
return value;
}
static void UnhandledExceptionTrapper(object sender, UnhandledExceptionEventArgs e)
{
Console.WriteLine(e.ExceptionObject.ToString());
Console.WriteLine("Press Enter to continue");
Console.ReadLine();
Environment.Exit(1);
}
}
}
If that gets run without .pdb file present it will dutifully catch the error and report on it.
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at ExceptionTest.Program.DoStuff(Int32 parameter)
at ExceptionTest.Program.Main(String[] args)
Press Enter to continue
Is there any way to include the point in user code at which the fault occured or is this simply not present in the executable (obviously some symbol information is included as we can see the DoStuff function name.
For example is there any way I could log int value = data[parameter];
in addition to the stack trace.