Exception line error

A

Adam

I apologize if this is an easy question, but I can't find
a way to do this.

I want the line number of where an error occurred to be
shown in a new exception's message when I use a try/catch
statement. Is there a way to get the line number where
error occurred when catching an Exception?

Example:
try
{
##code##
}
catch(Exception ex)
{throw new Exception(ex.Message + ##error line number##);}
 
N

Nicholas Paldino [.NET/C# MVP]

Adam,

There is not. The only way that this information will be given is if
the assembly has the debug symbols in it. If you want it otherwise, you
will have to insert the line numbers into your code.

Hope this helps.
 

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