Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should CodeContracts replace the regular ArgumentExceptions?

Could I start using CodeContracts instead of:

if (XXX == Y)
    throw new ArgumentException("bla bla");

How does it work if I develop a library and my library users do not use CodeContracts?

like image 588
jgauffin Avatar asked Jan 01 '26 08:01

jgauffin


1 Answers

Assuming that the code using code contracts is run through the binary rewriter, it will throw exceptions like code you posted. The re-writer goes through the code and replaces the contract code with argument checking etc. It's kinda like aspect oriented programming. It injects code to handle situations for you after you've compiled it.

If they don't use Code Contracts they will not get the benefit of having static analysis performed which is designed to look at the contract and warn them they might get an error based on the contract and their code.

Code Contracts

like image 101
kemiller2002 Avatar answered Jan 03 '26 21:01

kemiller2002



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!