filmov
tv
How to Handle Exceptions in Python - 60 Seconds to Code

Показать описание
Welcome to 60 seconds to code where I show you how to code in 60 seconds or less.
Today you will learn about exception handling. Exceptions are errors that occur in your code. If you know in advance that a piece of code might cause an error, you can gracefully handle the exception. For example, if you expect a file to exist but there is a possibility that it has been corrupted.
Step 4 – In line 3 type except FileNotFoundError as e: in line 4 type print(e). This except block will execute if the file you are looking to open does not exist.
Step 6 – Run your code to successfully print the contents of the file. Then try introducing an error in your code by changing the file name in the open function call and running the code again.
The code is available in a link in the description.
Congratulations, you have learned about exception handing. For your homework, create a different error in your code and write a different except block to catch that error and try to code a little every day because code is life.
Learn #exceptions and #exceptionhandling in #python #100DaysOfCode #301DaysofCode #60secondstocode
Today you will learn about exception handling. Exceptions are errors that occur in your code. If you know in advance that a piece of code might cause an error, you can gracefully handle the exception. For example, if you expect a file to exist but there is a possibility that it has been corrupted.
Step 4 – In line 3 type except FileNotFoundError as e: in line 4 type print(e). This except block will execute if the file you are looking to open does not exist.
Step 6 – Run your code to successfully print the contents of the file. Then try introducing an error in your code by changing the file name in the open function call and running the code again.
The code is available in a link in the description.
Congratulations, you have learned about exception handing. For your homework, create a different error in your code and write a different except block to catch that error and try to code a little every day because code is life.
Learn #exceptions and #exceptionhandling in #python #100DaysOfCode #301DaysofCode #60secondstocode