Exception Handling & Accurate Floats in Python by CodingXpertz

preview_player
Показать описание
Nobody wants their programs to crash. We should write code that anticipates the bad things a
user may enter to cause a crash and eliminate them. However some times the user may try to
access a database that doesn’t exist, or they simply refuse to follow instructions. That is where
exception handling comes in.
Through exception handling we can catch an error that would normally crash our program and
give the user the opportunity to do the right thing.
In this 1st example we’ll ask the user to enter a number, but if they refuse we will ask again by
catching and solving the error.
We will surround our problematic code with a try block. We will then try to catch the expected
error in an except block. If the user does something completely unexpected we will use an
expect block without defining a specific exception to catch all other exceptions.
Рекомендации по теме
visit shbcf.ru