110,533
社区成员
发帖
与我相关
我的任务
分享
try
{
int t = 1;
int i = 5 / --t;
}
catch (Exception e1)
{
System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(e1,true);
int i= st.GetFrame(0).GetFileLineNumber();
int j = st.GetFrame(0).GetFileColumnNumber();
string k = st.GetFrame(0).GetFileName();
}
static void Main(string[] args)
{
try
{
int t = 1;
int i = 5 / --t;
}
catch (Exception e)
{
int i = e.StackTrace.IndexOf("行号");
string s = e.StackTrace.Substring(i+3);
i = s.IndexOf(' ');
if (i != -1)
{
s = s.Substring(0, i);
}
//这里s已经存储了错误所在行号
}
}
try
{
throw new Exception();
}
catch (Exception e)
{
Console.WriteLine(e.StackTrace);
}