Raising and Handling Python Exceptions
source link: https://realpython.com/courses/raising-handling-exceptions/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
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:
You’ll learn about the basic use of a try
… except
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
try
…except
block - Use the additional keywords
else
andfinally
- Catch built-in exceptions
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK