Why is there no key specified with .NET KeyNotFoundException (in message/property)? Is it because of performance reasons? Is it because when Dictionary finds out there isnt any requested object by the hash it already doesnt know the context of the original key? I couldnt find an answer to this question anywhere.
C# – Why is there no key specified with .NET KeyNotFoundException
cdictionarynet
Best Answer
This may not be the official answer, but...
C# and VB.NET - the main .NET languages - are statically typed languages(yea, I know, they support dynamic typing, but still). This means properties in classes are typed. What would the type of
KeyNotFoundException.Key
be?If you wanted to properly support this, you'd have to use generics -
KeyNotFoundException<string>
andKeyNotFoundException<int>
. But this would complicate the API just so you can get information you already have.