请参见Creating 和 Throwing Exceptions.
在抛出内置异常时,它说:
不要扔系统.例外,系统.系统例外,系统.NullReferenceException或System.IndexOutOfRangeException故意从您自己的源代码中删除.
和
不要抛出一般异常
If you throw a general exception type, such as Exception or SystemException in a library or framework, it forces consumers to catch all exceptions, including unknown exceptions that they do not know how to h和le.
相反,要么抛出框架中已经存在的更派生的类型,要么创建自己的从Exception派生的类型."
这blog entry条也有一些有用的指导方针.
此外,FxCop代码分析将"不引发异常"列表定义为described here.它建议:
以下异常类型过于笼统,无法向用户提供足够的信息:
- System.Exception
- 系统应用程序异常
- 系统系统例外
The following exception types are reserved 和 should be thrown only by the common language runtime:
- 系统ExecutionEngineeException
- 系统IndexOutOfRangeException
- 系统NullReferenceException
- 系统OutOfMemoryException
So in theory you can raise any other framework exception type, providing you clearly underst和 the intent of the exception as described by Microsoft (see MSDN documentation).
Note, these are "guidelines" 和 as some others have said, there is debate around 系统IndexOutOfRangeException (ie many developers throw this exception).