有时候处理数据时总是会抛出一些莫名其妙的异常,因此我想知道导致的异常的具体数据是什么
在不破坏原来业务机制的情况下,可以通过抛出一个包含具体数据的新异常
但是新异常会覆盖掉真实的异常,堆栈只能定位到thow哪里,因此需要将真正的异常信息传递出去
static void Start() { string a = "abc"; try { Convert.ToInt32(a); } catch (Exception ex) { //1,输出异常的数据 //2,将捕获的异常传入到新创建的异常中,否则外面捕获到的异常的堆栈就只能定位到throw这里 throw new Exception($"将{a}转成数字时发生了异常," + ex.ToString()); } }