Is there a list of .Net Exception types and advice on when to use them?

我的未来我决定 提交于 2019-12-18 10:12:50

问题


Does anyone know of a list of .Net Exception types .e.g. ArgumentNullException and under what circumstances you should use them? At the moment I'm just guessing based on the type name but I would rather get it right.


回答1:


A list of them:

http://mikevallotton.wordpress.com/2009/07/08/net-exceptions-all-of-them/

As for the circumstance, it depends, most of the time they make sense based on their name and arguments. ArgumentNullException, for example, is usually used when checking method / constructor arguments for null values.

Then you have others such as FileNotFoundException, NullReferenceException, InvalidOperationException, as you can see they read very easily and should be used with common sense.

Update 1: as someone has suggested, they are also on MSDN:

http://msdn.microsoft.com/en-us/library/system.exception.aspx#inheritanceContinued

Here are views on common exceptions available:

http://weblogs.asp.net/jgaylord/archive/2009/07/08/common-and-all-system-exceptions-in-net.aspx

http://www.developerfusion.com/article/1889/exception-handling-in-c/3/

Update 2: as for usage, Microsoft has guidelines for reserved exception types:

http://msdn.microsoft.com/en-us/library/ms182338.aspx



来源:https://stackoverflow.com/questions/6676021/is-there-a-list-of-net-exception-types-and-advice-on-when-to-use-them

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!