Do codeContract only throw exceptions?
-
Wednesday, May 02, 2012 5:54 AM
Hi,
Just learning about codecontracts. It seems very neat and good if you want to throw exceptions.
What about if you dont want to throw exceptions and return a resultList if you like of all the errors?
Can this be done with codecontract?
thanks
Thanks for your help
All Replies
-
Wednesday, May 02, 2012 7:17 AM
Hi devBrix,
you can subscribe the Contracts.ContractFailed static event. You can process a contract failure on your own in the handler and then call e.SetHandled().
Hth.
-
Wednesday, May 02, 2012 8:04 AM
Hi
Thanks for your reply
What I want to do is
Use CodeContracts
When a contract fails I want to add the error to my ErrorList and return it.
Can I add to my own list in the eventHandler then?thanks
Thanks for your help
-
Wednesday, May 02, 2012 8:15 AM
In the event handler you can log the failure to some static list. After the code whose contract failures are to be monitored finishes, you can process the list - for example write it to a file etc.
What do you mean by "returning it"? Neither the contract nor the event handler can return a value.
- Marked As Answer by devBrix Wednesday, May 02, 2012 10:42 AM

