CodeAs follows:
Try{// Your code here}Catch(ExceptionEx ){Console. Writeline (ex. Message); system. diagnostics.StacktraceTrace =NewSystem. diagnostics.Stacktrace(EX,True);Console. Writeline (trace. getframe (trace. framecount-1). getmethod (). Name );Console. Writeline (trace. getframe (trace. framecount-1). getfilelinenumber ());Console. Writeline (trace. getframe (trace. framecount-1). getfilecolumnnumber ());}
A little simpler, you can use exception. tostring ().
Example output of ex. tostring:
System. invalidcastexception: Unable to cast object of Type 'Microsoft. Sharepoint. splist' to type 'Microsoft. Sharepoint. spdocumentlibrary '.
At getfolderlength. program. Main (string [] ARGs) in E: \ code \ CSHARP \ project1 \ Program. CS: line 110
The result of system. appdomain. currentdomain. basedirectory. tostring () is as follows:
E: \ code \ CSHARP \ project1 \ bin \ debug \
References:
Getting line numbers in exception stack trace in a Windows Service
Http://dnchannel.blogspot.com/2007/09/getting-line-numbers-in-exception-stack.html
System. Diagnostics. stacktrace or system. Diagnostics. stackframe for debugging? Why
Http://stackoverflow.com/questions/925737/system-diagnostics-stacktrace-or-system-diagnostics-stackframe-for-debugging-w
Caveats about system. Diagnostics. stacktrace
Http://blogs.msdn.com/jmstall/archive/2005/03/20/399287.aspx