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();
}
VulpesPosted Oct 15, 2014, 11:50 AM
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.
MarcPosted Oct 15, 2014, 11:58 AM
MarcPosted Oct 15, 2014, 11:39 AM
VulpesPosted Oct 15, 2014, 10:40 AM
But I'd guess that the Instance indexer returns null if it can't find the key.
So I'd try: