How to get error line number in c#? Anonymous User943106-Mar-2013Hi!Can any one help me?I want to get on which line exception are generated. Simply I want to stored error line number in C#.Please help me!Thanks in advance!c#c# Updated on 06-Mar-2013
AVADHESH PATEL
06-Mar-2013Hi Jacob!
You can try this way!
Create ExceptionHelper class as below
public static class ExceptionHelper
{
public static int LineNumber(this Exception e)
{
int linenum = 0;
try
{
linenum = Convert.ToInt32(e.StackTrace.Substring(e.StackTrace.LastIndexOf(":line") + 5));
}
catch
{
//Stack trace is not available!
}
return linenum;
}
}
get error line number as below
try
{
// do somthing here
}
catch(Exception ex)
{
int eln = ex.LineNumber();
}
I hope it resolve your problem