Exception 的處理並且提示錯誤的行數及方法

  • 5171
  • 0
  • C#
  • 2018-01-15

摘要:Exception 的處理並且提示錯誤的行數及方法

                catch (System.Data.SqlClient.SqlException ex)
                {
                    // 還原交易處理
                    transaction.Rollback();
 
                    string 目前行號 = new StackTrace(true).GetFrame(0).GetFileLineNumber().ToString();
                    string currentName = new StackTrace(true).GetFrame(0).GetMethod().Name;
                    string callName = new StackTrace(true).GetFrame(1).GetMethod().Name;
 
                    MessageBox.Show("確認失敗 !!" + "錯誤行數" + 目前行號 + "呼叫方法" + currentName + " |" + ex.Message.ToString(), "訊息提示"MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                catch (System.Exception ex)
                {
                    // 還原交易處理
                    transaction.Rollback();
                    //MessageBox.Show(ex.Message.ToString());
                    string 目前行號 = new StackTrace(true).GetFrame(0).GetFileLineNumber().ToString();
                    string currentName = new StackTrace(true).GetFrame(0).GetMethod().Name;
                    string callName = new StackTrace(true).GetFrame(1).GetMethod().Name;
 
                    MessageBox.Show("確認失敗 !!" + "錯誤行數" + 目前行號 + "呼叫方法" + currentName + " |" + ex.Message.ToString(), "訊息提示"MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

 

興滿逸筑2013年全新完工,位於恆春鎮外圍離市區只要2分鐘車程,有豪華的外觀、有美麗的庭院、也有溫馨舒適的房間,這裡車流量不多,空氣不錯,適合家族或成群結黨的朋友們一同旅遊的好地方。

http://sinmaniz.tw/index.html