Python: Try, Except, Finally Example (Code In Description)

Опубликовано: 16 Сентябрь 2022
на канале: Make That Work
165
6

If at first you don't succeed, try, try and ... try, except and finally!

This video goes through a quick example to show you how to step up your error handling in your Python code by using try, except and finally blocks.

It's unavoidable. Your code will have the odd error. But an error shouldn't crash your program without a warning. We should handle errors and exceptions properly

One thing we can do is use try, except, finally statements in our code that catch errors without crashing to the terminal.

Here's the code I used:
val = 5

try:
print("val = ", val)

print("val + 5 = ", val+5)

except Exception as e:
print("There was an error!")
print("ERROR: ", e)

finally:
print("this is the last statement")


На этой странице сайта вы можете посмотреть видео онлайн Python: Try, Except, Finally Example (Code In Description) длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Make That Work 16 Сентябрь 2022, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 165 раз и оно понравилось 6 зрителям. Приятного просмотра!