-1

i found a double standarts in TryPopRange ConcurrentStack methods. The name of method TryPopRange says, that it uses the TryXXX pattern, which shouldn't give you exceptions. But TryPopRange method can throw you 3 differents exceptions (ArgumentEx, ArgumentNullEx, ArgumentOutOfRangeEx). Okay, it's normal to check incoming parameters. But, if concurrent stack will be empty, i will have exception. If one thread will read all data, and my thread will use TryPopRange method i will have only exception for my read attempt.

I can understand, why they did this??

Kirch
  • 1

1 Answers1

0

Do you refer to this overload of TryPopRange?

public int TryPopRange(T[] items, int startIndex, int count);

// Exceptions:
//   T:System.ArgumentNullException:
//     items is a null reference (Nothing in Visual Basic).
//
//   T:System.ArgumentOutOfRangeException:
//     startIndex or count is negative. Or startIndex is greater than or equal to the
//     length of items.
//
//   T:System.ArgumentException:
//     startIndex + count is greater than the length of items.

These exceptions are not related to the amount of items in the ConcurrentStack collection, but to the size of the supplied T[] items argument. You are expected to pass consistent values as arguments, so you can't pass an items array of size 10 and a startIndex of size 11.

Theodor Zoulias
  • 34,835
  • 7
  • 69
  • 104