Exceptions and Preconditions
- The most common use of preconditions is to demand a
property because it would be hard or expensive to check
it.
- It is an engineering judgment. What is the cost of the
check? what is the scope of the method?
- For example, binary search methods require that the array
be sorted, otherwise they could not deliver $O(\log n)$. If
they had to sort, it would be $O(n\cdot\log n)$.
- Even when using a precondition, you might want to check it
if it can de done speedily and easily.
José M. Vidal
.
7 of 16