What could go wrong if you selected a reserved exception in C #?

FxCop throws a CA2201 rule violation if you throw a System.IndexOutOfRangeException into your code ( see link ). The rationale for this is that a System.IndexOutOfRangeException "reserved and should only be selected by the total execution time" in accordance with the documentation.

But what could actually go wrong if you throw a System.IndexOutOfRangeException ?

+7
source share
1 answer

Nothing.

From a technical point of view, completely eliminate this exception. Nothing will break if you do it.

But keep in mind that you should throw a System.IndexOutOfRangeException only if you encounter a System.IndexOutOfRangeException first place, because otherwise this exception would not be appropriate, since it is very clear which type of this exception should be used for . MSDN status for System.IndexOutOfRangeException :

The exception that occurs when trying to access an array element with an index that is outside the array. This class cannot be inherited.

+4
source

All Articles