新建一winform项目,放上两个radiobutton 这两个radiobutton事件都指向同一个事件rdTTT_CheckedChanged 代码如下: private void rdTTT_CheckedChanged(object sender, EventArgs e) { asdf(); } private void asdf() { int u = 0; u = 123 / u; } 你点一下,visual studio的异常不会定位到u = 123 / u;.不信你试试 那如果要定位出错行呢.那就这样写: private void rdTTT_CheckedChanged(object sender, EventArgs e) { try { asdf(); } catch(Exception ex) { throw new Exception("ddd",ex);//这行一定要这么写,要不然异常的堆栈会没有了 } } 然后在 static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) { throw new NotImplementedException(); } 中的e参数的innerexception中就能找到出错行. ---------------------------------------------- |
|