1
I create a lot of programs with a graphical interface and a lot of user interaction. I always exaggerate on try
/except
. What are the impacts of excessive use?
1
I create a lot of programs with a graphical interface and a lot of user interaction. I always exaggerate on try
/except
. What are the impacts of excessive use?
2
In Python the culture is to let the mistake happen and then treat, so it kind of doesn’t have much choice in what already exists and probably in third-party libraries that follow the same philosophy. You could do different in your things.
There is usually a loss of performance, but Python is not the performance language. And in Python the cost isn’t that high because it has a simplified exception model. The cost occurs even if you do not use anything, the damage is already done you capturing or not. And of course, if the error happens you have to capture.
I still think that if I can avoid the error before it occurs I find it advantageous to do so.
One of the problems of abusing it is that exception is a goto
that you don’t even know where you’re going. It disrupts the code, it’s not so easy to get it right unless you can organize it really well. Then the exception would, in theory, be less necessary.
I have learned new things from Python and am finding this to be "the least" of the problems in it. I still wouldn’t abuse it, but it’s not a capital crime.
I have not seen code, I have not seen an example of what is exaggeration. If it is exaggeration even the code gets convoluted and this is never good. It is used in place of a simple if
The code is complicated using the wrong mechanism. Everything you use has to be justified, if you don’t know why you used it, and it’s a valid justification, don’t use it. Better to do wrong by omitting something you don’t know how to use than to make a mistake because you used something without knowing why.
A bigger problem is to abuse the senseless capture. If you catch mistakes that you do not know how to deal with obviously you are only pretending to be careful. It will probably make the user experience worse by not doing what they need or doing something generic that is specific. Imagine your user receiving an "error!" message. Your mother’s ear will warm up.
Browser other questions tagged python exception
You are not signed in. Login or sign up in order to post.
Related: Exceptions consume a lot of processing. Truth or legend? | Best way to deal with Exceptions | Why should we avoid returning error codes?
– Woss