0
Why exception important?
2 odpowiedzi
+ 2
When your code fails to run, you are able to fix it quicker if you know different types of exceptions and main reasons that cause them. Moreover, later when you'll write some larger code, you will want to implement exception catching so that your program will not crash when something unusual happens.
0
We use exception handler to prevent wrong or undesirable input(s) to our programs, to improve programs stability and to generate necessary errors whenever the rule(s) violated.
example:
while True:
try:
number = int(input("Enter an integer number please"))
break
except ValueError:
print("Sorry you have to enter an integer number")
except:
print("Unknow error occurred")
print("Your input is valid,thank you")
from the example above when user prompted to enter a number and then the user enters character 'a' or string "number" the program will try to check if it is a valid which is not in this case so the first error " Sorry you have to enter an integer number" will be printed and program will ask the user to enter the number until the input is valid..... As we can see the program is stable and generates the necessary error which will help the user to provide a valid input......Thank you.