Tuesday, December 21, 2021

Raising and Handling Python Exceptions

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:

Diagram explaining try except else finally statements

You’ll learn about the basic use of a tryexcept block, as well as how to extend it using else and finally.

In this course, you’ll learn how to:

  • 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 tryexcept block
  • Use the additional keywords else and finally
  • Catch built-in exceptions

[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]



from Real Python
read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...