結構化異常處理(三)系統級異常和應用程式級異常

來源:互聯網
上載者:User

標籤:style   class   blog   code   color   strong   

一、系統級異常

1.准去的說,.NET平台引發的一場應被稱為系統異常。這些異常被認為是無法修複的致命錯誤。

2.系統異常直接派生自名為System.SystemException的基類,該基類派生自System.Exception。

SystemException除了一組自訂的建構函式不添加任何功能。

public class SystemException :  Exception

{

  //各種建構函式

}

3.當一個異常類型派生自System.SystemException時,我們就能夠判斷引發該異常的實體是.NET運行庫而不是正在執行的程式庫代碼。

可以通過is關鍵字來驗證這個結論:

NullReferenceException nullRefEx = new NullReferenceException();Console.WriteLine("NullREferenceException is a SystemException? : {0}", nullRefEx is SystemException);

二、應用程式級異常
1.自訂異常應當派生自System.ApplicationException類型:

public class ApplicationException : Exception

{

  //各種建構函式

}

就像系統異常一樣,應用程式異常並不在一組建構函式外再定義其他任何成員。

2.從功能上講System.ApplicationException的唯一目的就是標識出錯誤的來源。

當讀者處理一個派生自System.ApplicationException的異常時,可以設想異常是由正在執行的應用程式程式碼程式庫引發的,而不是由.NET基礎類庫或.NET運行時引擎引發的。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.