5 ms·
Because all systems try to handle several kinds of unexpected behavior in the exactly the same way - invalid arguments (e.g. 'x == null') - code logic (e.g. 'i
by why_Mr_Anderson 6y ago
Because all systems try to handle several kinds of unexpected behavior in the exactly the same way
- invalid arguments (e.g. 'x == null')
- code logic (e.g. 'if (x.salary < 0) ...')
- external errors (e.g. 'out of memory')
I'd argue that only the 3rd kind is actually 'exception', it's completely out of program's control.
Code contracts are wonderful way of dealing with 1st and 2nd kind, sadly they didn't catch up and remains mostly unknown. They are vastly superior to tests and also serve as much better way to document intent of the code, how the author expected the code to work.
- nerdponx 6y agoUnless you have dependent types, isn't a contract just syntactic sugar for an if/else that either raises and exception or returns an error code?