Hi!
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!
Hi!
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!
Hi 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