PYTHON PROGRAMMING: ADVANCED > MISSION 2 > EXCEPTION HANDLING

Exception Handling

In the previous module, you learned about object-oriented programming and how Python is considered an object-oriented language. To continue this Python Programming Advanced course, you will learn about exception handling. 

When programming, we usually try to avoid writing code that will generate errors. Even so, errors can be quite useful to us because they tell us what went wrong with our code. Exception handling can help catch these useful errors and handled gracefully so the program doesn't crash.

While learning about exception handling, you will determine the optimal length of a chopstick. To test your knowledge of the concepts of object-oriented programming, you will create your own Chopstick class using what you have learned in the previous module. We will then use exception handling to extend our Chopstick class to account for the event that bad data is read in.

As you work through this exception handling module, you’ll get to apply what you’ve learned from within your browser – there's no need to use your own machine to do the exercises. The Python environment inside of this course includes answer checking so you can ensure that you've fully mastered each concept before learning the next.

Objectives

  • Leanr to organize code.
  • Learn to create and use a class.
  • Learn how to handle edge cases using 'except'.

Mission Outline

1. Introduction: The Science of Chopsticks
2. Organizing Our Code
3. Creating the Chopstick Class
4. Storing the Trials in the Chopstick Class
5. Calculating Average Efficiency With a Method
6. Overview of Exceptions
7. Handling Exceptions
8. Handling Bad Data in the Trial Class
9. Handling Bad Data in the Chopstick Class
10. Handling Lengths Outside of the Data Set
11. Converting Lengths to Chopstick Instances
12. Overloading Comparison Operators
13. Takeaways

Take a Look Inside