Raising and Handling Python Exceptions
Martin Breuss
33:42
Description
A Python program terminates as soon as it encounters an error. In Python, an error can be a syntax error or an exception.
In this course, you’ll learn what an exception is and how it differs from a syntax error. After that, you’ll learn about raising exceptions and making assertions. Then, you’ll learn how to catch exceptions to prevent your program from unintentionally ending and to change the control flow of your program:
You’ll learn about the basic use of a try … except block, as well as how to extend it using else and finally.
What You'll Learn?
- Differentiate exceptions from syntax errors
- Use the
assert
keyword to check if a certain condition is met - Write custom exceptions that subclass
Exception
- Catch exceptions with a
try
…except
block - Use the additional keywords
else
andfinally
- Catch built-in exceptions
More details
User Reviews
Rating
Martin Breuss
Instructor's CoursesAs someone who learned programming primarily through online resources, I feel that I have a good understanding of how important high quality learning material is.
With a background in education, I worked as a coding mentor, code reviewer, curriculum developer, and bootcamp instructor. Quality education and figuring out how to have fun while learning unfamiliar topics effectively has always been a big topic in my life. Real Python provides all that, and I’m happy that I can contribute.
In my day job I create online courses and teach on-site bootcamps around the world with CodingNomads. This position keeps me traveling, teaching, learning, discovering new places and new aspects of Python, as well as getting to know interesting and motivated students year-round.
When you learn to program, you’re learning to instruct a universal tool. People have described programming as the literacy of the 21st century, and I think that there’s something to that idea.
That doesn’t mean that you need to become a full-time software developer to apply your programming skills productively. Most likely there is way how your interests can benefit from being able to skillfully instruct your personal universal tool. And Python is a great language to get started with and also to keep going.
I’m happy to help out with thoughts and resources as well as encouragement.
If you’re stuck, remember that everyone gets stuck and if you feel you don’t know much, keep in mind that most of us feel that way quite often. Take a break, maybe go on a walk outside or do what it takes for you to keep yourself feeling good.
It’s easier to stick with something for the long term when you’re finding enjoyment in what you do. Remember that learning anything new is more of a marathon than a sprint. :)

Real Python
View courses Real Python- language english
- Training sessions 9
- duration 33:42
- Release Date 2023/01/05