Why exception important? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

Why exception important?

24th Sep 2016, 3:04 PM
Abdul Azeez
Abdul Azeez - avatar
2 ответов
+ 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.
9th Oct 2016, 2:36 PM
Daniel
Daniel - avatar
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.
24th Oct 2016, 11:51 AM
Isack T Nicholaus
Isack T Nicholaus - avatar