|
|
|
|
|
by pilif
5575 days ago
|
|
Sure I can use asserts. But I'm as likely to forget the assert() as I am to forget to check the return value. And even if I did: If you consider the faulty main() in the linked article: How would you use assert() there to make sure that result as used after the call to foo() is actually usable? If foo() returns -1 (because any of the calls to divide returned -1) then result is undefined. |
|
Just to finish out the example to show how much cleaner asserting is compared to error handling:
That's not to say that error handling doesn't have its place, but it should only be used for data that you can't anticipate.