try { int i = 0; int a = 10 / i; } catch (Exception ex) { /** * 1.異常消息 * 2.異常模塊名稱 * 3.異常方法名稱 * 4.異常行號 */ String str = ""; str += ex.Message + "\n";//異常消息 str += ex.StackTrace + "\n";//提示出錯位置,不會定位到方法內部去 str += ex.ToString() + "\n";//將方法內部和外部所有出錯的位置提示出來 MessageBox.Show(str); }
記錄下來主要是為了記錄系統異常日志所使用