+ 4

except

the lesson using except in python is confusing me , I am not mind it, why use it?

24th Apr 2017, 10:37 AM
Nasibillo Muhamedov
Nasibillo Muhamedov - avatar
1 Answer
+ 13
Proper handling of exceptions raised by the program is essential. By enveloping part of your code in try/except clause you can tell Python what to do, if an exception (error) is raised. If you let the user specify a number which you later would like to divide by, if the user enters something which is not a number or enters 0, the division will fail and the code *stops*. It has to be run again to work, but will start from the beginning. This last thing is crucial - if you don't want your code to stop and its work to be lost, you have to ensure it handles all possible errorneous situations well.
24th Apr 2017, 10:49 AM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar