Error Handling
- Traditional approach: Method returns error code
- Problem: Forget to check for error code
- Failure notification may go undetected
- Problem: Calling method may not be able to do anything about failure
- Program must fail too and let its caller worry about it
- Many method calls would need to be checked
- Instead of programming for success
x.doSomething()
you would always be programming for failure:
if (!x.doSomething()) return false;