I think it is better to add assert at the beginning of a function.