Para ver la StackTrace una excepción dado, utilizar e.StackTrace
Si necesita información más detallada, puede utilizar la clase System.Diagnostics.StackTrace (aquí hay un código para probar):
try
{
throw new Exception();
}
catch (Exception ex)
{
//Get a StackTrace object for the exception
StackTrace st = new StackTrace(ex, true);
//Get the first stack frame
StackFrame frame = st.GetFrame(0);
//Get the file name
string fileName = frame.GetFileName();
//Get the method name
string methodName = frame.GetMethod().Name;
//Get the line number from the stack frame
int line = frame.GetFileLineNumber();
//Get the column number
int col = frame.GetFileColumnNumber();
}
Esto solo funcionará si hay un archivo pdb disponible para el ensamblaje. Vea las propiedades del proyecto - pestaña de compilación - Avanzado - Selección de información de depuración para asegurarse de que hay un archivo pdb.
¿Cómo se compila ese código? –
no lo acabo de hacer para mostrar como un ejemplo – Crash893
posible duplicado http://stackoverflow.com/questions/8338495/how-to-get-error-line-number-of-code-using-try-catch –