I'm having an issue that if a user enters a none existing catagory or typing error, and that catagory is not listed it causes the application to crash. I've narrowed it down to this particular piece of code but want to know what type of condition I can use that if the instance "key" cannot be found to throw an exemption.
This is what I have so far...
myDecryptor.DomainKey key = myDecryptor.DomainKey.Instance[dmCategory.ToLower()]
//what I've added
if (key) //looking for a condition that would throw this exception if key is not found
{
throw new Exception();
}

VulpesRank #55 · 29.2K reputationPosted Oct 15, 2014, 7:50 AM EDT
Otherwise, if it's not a fatal error, you could just continue with the program after taking any remedial action.
Personally, I HATE throwing exceptions and always try to continue the program or, at the very least, make a graceful exit.
VulpesRank #55 · 29.2K reputationPosted Oct 15, 2014, 6:40 AM EDT
But I'd guess that the Instance indexer returns null if it can't find the key.
So I'd try:
Marc176 reputationPosted Oct 15, 2014, 7:39 AM EDT
Marc176 reputationPosted Oct 15, 2014, 7:58 AM EDT