Lets say that you have a business object whose current state implies that there is some kind of a bug in your code. Or basically any scenario where you are working with your own data but it is in a state that should never occur violating some rules. I like to typically check for such conditions and assumptions because it allows me to catch bugs early on closer to their source. However, what is the best practice if such a logic check fails?
I know that Debug.Assert statements are very handy for this, however I'm not very fond of them because they only appear in debug mode and not in the testing or release phase which can obviously still contain many such bugs. I'd much rather be informed that this check is failing as opposed to trying to debug a problem that occurs much afterwards in the code. The solution to me looks like throwing an exception of some kind. Is this a good idea?