+ 4
what is the use of exception in progaraming???
8 Réponses
+ 11
you can use exception to by pass an error without stoping the running program
+ 5
The Exceptions are the way to deal with errors in Python.
When you want to be a good programmer in Python, you REALLY have to know how to use them, as they are at the foundation of the language.
+ 3
If proper used, exceptions makes your code cleaner. Instead of doing checks everywhere, you can assume things are right and if an error arises you caught it using a exception. For example you do not need to check array indexes or the denominator of a division, if theses errors occurs treat them them with exceptions. Of course some checks are still needed, but they will related to your problem. Even on this case exceptions can simplify your code because you can raise your own exceptions.
+ 2
Just because you ask for a number doesn't mean everyone will provide one. Programs crash (or worse) when they don't sanitize inputs...or fail to anticipate exceptional, interrupting events.
+ 1
I will just give one example where it is useful: when you try to access a temporary file, either you check whether every single condition on it is expected and Behold! the file is gone...
Or you can just try to access it and see if there's a problem later.
+ 1
It allows you to decouple the actions and the handling of errors that might arise during those actions.
Enabling you to concentrate error handling in one place instead of peppering your code with it. Also, sometimes the code that knows what to do about an error is a few levels above the actual function that caused it. Without exceptions, all the functions at intermediary levels would have to know all the error types and explicitly pass them back to callers.
+ 1
exception is use to indicate what's errors in our program and validation of data types.
+ 1
It is particularly used for raising errors when input by the user is not right