+ 4
except
the lesson using except in python is confusing me , I am not mind it, why use it?
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.