What are the impacts of Excessive Use of Try / Except?

1

I create a lot of programs with graphical interface and a lot of interaction with the user. I always exaggerate in try / except . What are the impacts of overuse?

    
asked by anonymous 13.07.2018 / 15:41

1 answer

1

In Python the culture is letting the error happen and then dealing, so kind of does not have much choice in what already exists and probably in third party libraries that follow the same philosophy. You could do differently in your things.

There is usually performance loss, but Python is not the language of performance. And in Python the cost is not even that high because it has a simplified exception model. The cost occurs even if you do not use anything, the damage is already done by you capturing or not. Of course, if the error happens you have to capture it.

I still think that if you can avoid the error before it happens, I think it is advantageous to do so.

One of the problems of abusing this is that the exception is goto that you do not even know where you are going. This de-structures the code, it's not so easy to do right, unless you know how to organize very well. So the exception would in theory be less necessary.

I've learned new things from Python and I'm finding this to be the "minor" of the problems in it. I still would not abuse it, but it's not a capital crime.

I did not see code, I saw no example of what is overkill. If it is too much exaggeration the code becomes convoluted and this is never good. If it is used instead of a simple% code, the code is complicated using the wrong mechanism. Everything you use has to be justified, if you do not know why you used it, and it's a valid justification, do not use it. Better to do wrong by omitting something you do not know to use than to err because you have used something without knowing why.

A major problem is to abuse mindless capture. If you catch mistakes that you do not know how to deal with obviously you're just pretending to be careful. It will probably worsen the user experience by failing to do what it needs or doing something generically that is specific. Imagine your user getting an "error!" Message. Your mother's ear will warm.

    
13.07.2018 / 17:55