retrying icon indicating copy to clipboard operation
retrying copied to clipboard

The blank except clause is unintuitive

Open d0ugal opened this issue 11 years ago • 4 comments
trafficstars

Using a blank except: is unintuitive as it catches KeyBoardInterrupt exceptions too, this means if you try to ctrl+c the code it wont work (unless you do it enough times to hit a limit etc.)

This should be changed to except Exception: which will then catch the vast majority of exceptions that inherit from this. Otherwise you get all exceptions that inherit from BaseException which includes KeyboardInterrupt.

Alternatively it would be useful to add a parameter to retry on specific exceptions (and their subclasses).

@retry(on_exception=requests.exceptions.HTTPError) @retry(on_exception=socket.timeout) @retry(on_exception=BaseException) etc. etc.

The added beifit here is that you state what you want to catch and don't accidentally supress other exceptions.

This change would however be slightly backwards incompatible. The alternative would be to remaind a default to BaseException but allow the user to change this.

d0ugal avatar Sep 22 '14 09:09 d0ugal

It may also be usefull to have a way to give a logger to log exceptions ?

JulienPalard avatar May 16 '15 20:05 JulienPalard

+1 on the logger object

banjoh avatar Sep 01 '16 11:09 banjoh

FWIW, I have met my own needs with a small project: http://d0ugal.github.io/retrace/ - I don't have logging support, but that sounds like a good idea.

I am going to unsubscribe from this issue now, but leave it open should it be useful to the project.

d0ugal avatar Sep 01 '16 11:09 d0ugal

Awesome. I'll check it out.

banjoh avatar Sep 01 '16 12:09 banjoh