I prefer exceptions due to statements, because if it should be like that, and it isnβt, I want to know about it so that I can fix it, and the coverage that we get in debug mode is nowhere near real use or reach, so just using Debug.Assert is not enough.
Using statements means that you will not add bloat to your release code, but that means you can find out when and why these contracts will break if you catch them in the debug build.
Using exceptions means that you find that the contract is terminated whenever it happens, is debugged or released, but it also means that your version of the assembly contains more checks and code.
You can use the inbetween approach and use Trace to track the pre and post conditions for some application log that you could use to debug problems. However, you will need a way to collect log data to find out what problems your users are facing. It is also possible to comb this with exceptions, so you get exceptions for more serious problems.
The way I see it is that if the contract is worth it to justify, then it is worth throwing an exception when it breaks. I think a little up to the opinion and the target application. If you make exceptions, you probably want some form of incident reporting system to provide crash reports when the exceptions raised remain unhandled.
source share