問題描述
在 .NET 解決方案中創建異常類時的最佳做法是:從 System.Exception
或 System.ApplicationException
派生?
What is best practice when creating your exception classes in a .NET solution: To derive from System.Exception
or from System.ApplicationException
?
推薦答案
根據框架設計指南一書中的 Jeffery Richter:
According to Jeffery Richter in the Framework Design Guidelines book:
System.ApplicationException
是一個不應屬于 .NET 框架的類.
System.ApplicationException
is a class that should not be part of the .NET framework.
它的目的是為了有一些意義,因為您可以潛在地捕獲所有"應用程序異常,但沒有遵循該模式,因此它沒有任何價值.
It was intended to have some meaning in that you could potentially catch "all" the application exceptions, but the pattern was not followed and so it has no value.
這篇關于我應該從 .NET 中的 Exception 或 ApplicationException 派生自定義異常嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!