O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required