When KeyNotFoundException is thrown, how do I see which key wasn’t found?
Custom exception: class WellknownKeyNotFoundException : KeyNotFoundException { public WellknownKeyNotFoundException(object key, string message) : this(key, message, null) { } public WellknownKeyNotFoundException(object key, string message, Exception innerException) : base(message, innerException) { this.Key = key; } public object Key { get; private set; } } Handy extension method: public TValue GetValue<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key) { … Read more