ArgumentOutOfRangeException

Similar in spirit to the IndexOutOfRangeException for arrays, this exception type is used to signal a supplied argument is outside some range. Once more, it typically indicates sloppy input validation on the side of the caller, which should be avoidable in general.

Examples of the use of this exception type include the various collection data types in System.Collections and its sub-namespaces:

var lst = new List<int> { 1, 2, 3 };int thereIsNoThirdElement = lst[3];

Use of the exception type for your own APIs is straightforward using constructors similar to the ones seen for ArgumentException (with the paramName coming first). As a little reminder, keep in mind that argument and index are distinct concepts. Use of this ...

Get C# 5.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.