try
{
int t = 1;
int i = 5 / --t;
}
catch (Exception ee)
{
int i = ee.StackTrace.IndexOf("行号");
string s = ee.StackTrace.Substring(i + 3);
i = s.IndexOf(' ');
if (i != -1)
{
s = s.Substring(0, i);
}
int exceptionLine = Convert.ToInt32(s);//错误行号
}
此方法只适合中文状态查找!如果有更好的方法,欢迎留言。