I basically want to make sure I incorporate all exception handling possible for ArrayDictionary below.
What are all the possible exception handling you can do for the dictionary and dictionary arrays below. I know a few contraints off the top, All three Dictionaries must have the number of items or count which is 5 items each after items are being added. If not we can't continue. Another contraint will be to ensure that the dictionary count is three. and you can also check is dictionary is not null.
What are more checks and balances or exception handling?
review the next reply.
Loading
VulpesPosted Jan 25, 2012, 4:03 PM
David SmithPosted Jan 25, 2012, 3:23 PM
//Validating each data array dictionary item count.
foreach (var arrayDataDictionaryItem in ArrayDataDictionary)
{
IsArrayDataDictionaryValidated = (ArrayDataDictionary[arrayDataDictionaryItem .Key.ToString()].Count != 5) ? false : true;
if (!IsArrayDataDictionaryValidated )
{ throw new NotImplementedException("Array dictionary primary key " + arrayDataDictionaryItem .Key.ToString() + " does not implement 1101 items: "); }
}
VulpesPosted Jan 25, 2012, 10:31 AM
Secondly, there's no need to call ArrayDictionary.Clear() because you've only just instantiated it in the previous line and it must therefore be empty.
As far as error handling is concerned you only need to check that the 3 array arguments are not null and have a length of 5. As far as I can see nothing else can go wrong:
David SmithPosted Jan 25, 2012, 4:15 AM
public Dictionary
ContructArrayDictionar(ADict1 [], ADict2 [], ADict3 [])
{
ArrayDictionary = new Dictionary
ArrayDictionary.Clear();
foreach (ArrayType arrayDictionaryItem in Enum.GetValues(typeof(ArrayType)))
{
ArrayDictionary .Add(arrayDictionaryItem .ToString(), new List
switch (arrayDictionaryItem )
{
case ArrayType.ArrayType1:
foreach (var ADict1Item in ADict1 )
{
ArrayDictionary[arrayDictionaryItem .ToString()].Add(ADict1Item );
}
break;
case ArrayType.ArrayType2:
foreach (var ADict2Item in ADict2)
{
ArrayDictionary[arrayDictionaryItem .ToString()].Add(ADict2Item );
}
break;
}
}