How to get source code during exception?

S

samtilden

During my code's processing of an exception, I would like to format the
exception myself.

I can get almost everything (I can get exception itself, stack trace,
file name, line number, method, parameters) but cannot seem to get the
source code where the exception occurred.

The ASP.NET exception handler does display the source code, but I
cannot seem to get it myself and, hence, display it myself.

Through what objects (e.g., System.Diagnostics, System.Reflection,
etc.) do I need to go through in order to get the source code?

P.S. Yes, I compile in Debug mode and, yes, there a .pdb file
available, if that helps.

Thank you.
 
B

Bruce Wood

During my code's processing of an exception, I would like to format the
exception myself.

I can get almost everything (I can get exception itself, stack trace,
file name, line number, method, parameters) but cannot seem to get the
source code where the exception occurred.

The ASP.NET exception handler does display the source code, but I
cannot seem to get it myself and, hence, display it myself.

Through what objects (e.g., System.Diagnostics, System.Reflection,
etc.) do I need to go through in order to get the source code?

P.S. Yes, I compile in Debug mode and, yes, there a .pdb file
available, if that helps.

Thank you.

I believe that the information displayed in the stack trace (function
names, argument lists) is formatted from Reflection data. The only
exception would be the line numbers, which are probably discovered by
ferreting around in the .pdb file.
 
J

John Vottero

During my code's processing of an exception, I would like to format the
exception myself.

I can get almost everything (I can get exception itself, stack trace,
file name, line number, method, parameters) but cannot seem to get the
source code where the exception occurred.

You have the filename and line number, open that file and read to that line.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top