是否有一个.Net异常类型列表和建议何时使用它们? [英] Is there a list of .Net Exception types and advice on when to use them?

查看:188
本文介绍了是否有一个.Net异常类型列表和建议何时使用它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道.Net异常类型的列表。 ArgumentNullException 在什么情况下你应该使用它们?目前我只是根据类型名称猜测,但我宁愿得到正确的。

解决方案



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



As在这种情况下,这取决于大多数时间他们的名字和论据是有意义的。例如,当检查null值的方法/构造函数参数时,通常会使用ArgumentNullException 。



然后你有其他人例如 FileNotFoundException NullReferenceException InvalidOperationException 看到他们阅读非常容易,应该常识地使用。



更新1:,有人建议,他们也在MSDN上: / p>

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



以下是常见的例外情况: / p>

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



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



更新2:关于使用情况,Microsoft已为保留的异常类型指定: / p>

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


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.

解决方案

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

这篇关于是否有一个.Net异常类型列表和建议何时使用它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆