Day 20
For Next Time
On Friday you’ll be sending your code to instructors for a code review. We’ll work on a framing document for the exercise in class on Friday, but for now you should make sure you have a body of work completed and committed before then.
Exceptions
- Exception notes
- Use exceptions to represent exceptional cases.
- Raising an exception is an alternative to returning a value.
- Use exceptions when there’s no value it makes sense to return.
- A returned value must be handled by the caller.
- An may can be handled by the caller, the caller’s caller, etc. It is passed through functions in the call chain between the code that raises the exception and the code that handles it.
- Catch a specific exception. Catching all exceptions hides errors from the developer.
Assertions
- Assertion notes
- Use the assert statement to debug.
- An assertion error gets raised when a bug is encountered.
- Not used to catch runtime errors.
- It is not like print(‘statement’) so be careful to omit ‘()’.