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
Liked By
Write Answer
How to get error line number in c#?
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy
Join MindStick Community
You have need login or register for voting of answers or question.
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