Reliable code
Handling problems you expect, reporting problems clearly, proving that code works, and finding bugs calmly.
About 7 hours of study
Learning objectives
- Handle expected errors with try and except
- Raise clear errors from your own code
- Write tests that include edge cases
- Debug with a repeatable method
Lessons
- 1
Errors and exceptions
Read error messages, and handle expected problems with try and except.
- 2
Raising your own errors
Signal problems with raise, define your own exception classes, and clean up with finally.
- 3
Testing your code
Check that functions work with assert, think about edge cases, and read a failing test.
- 4
Debugging
Find bugs systematically: reproduce, watch the values, form a guess, and test it.
Module practice
- Double it, safelyEasy
- Safe divisionMedium
- A hundred shared outHard
- Password checkEasy
- Validate agesMedium
- An account that refusesHard
- Is it sorted?Easy
- Keep it in rangeMedium
- A median that does not breakHard
- Fix the averageEasy
- Fix the range totalMedium
- Fix the searchHard