In this section, you've learned about exceptions in Python. You learned how to:
- Catch exceptions with
tryandexcept - Handle exceptions in different ways
- Use the
exceptand thefinallykeywords - Raise exceptions
- Write custom exceptions
You also learned about when and how to use exceptions in Python and when you should better avoid using them.
You can improve the stability of your programs with exceptions, and they are a valuable tool in your software developer's tool belt. If you feel like you want to dive deeper, then take a look at some of the additional resources to solidify your understanding:
Additional Resources
- Python Documentation: Built-in Exceptions
- Official Python TutorialErrors And Exceptions
- Official Python Tutorial: User-Defined Exceptions
- Real Python: Python Exceptions: An Introduction
- Julien Danjou: Full Exception Guide
- Corey Schafer on YouTube: Python Exceptions
Another important tool to improve the stability of your code and make it more attractive for other developers to use is tests. Professional software development is a lot about writing good tests and making sure your code runs the way it's supposed to run. In the next section, you'll learn about how to implement tests in your Python programs.