using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TryCatch
{
class Program
{
static void Main(string[] args)
{
try
{
int b = int.Parse(null);
}
catch (Exception e)
{
//InnerException 获取对象实例(ef实体错误的时候非常好使)
string efError = e.InnerException.ToString();
//获取调用堆栈上的直接框架的字符串表示形式 StackTrace
//获取处错误文件的地址
string location = e.StackTrace.Substring(e.StackTrace.IndexOf("位置") + 2, e.StackTrace.IndexOf("行号") - e.StackTrace.IndexOf("位置") - 2);
//获取处错误文件的行数
string row = e.StackTrace.Substring(e.StackTrace.IndexOf("行号") + 2, e.StackTrace.Length - e.StackTrace.IndexOf("行号") - 2);
Console.WriteLine("错误发生在文件{0}第{1}行", location, row);
Console.ReadKey();
}
}
}
}
关于Try Catch的记录
最新推荐文章于 2022-01-27 21:48:56 发布