GeneratorExit should derive from BaseException, not Exception

Terry Reedy tjreedy at
Tue Aug 21 05:37:00 CEST 2007

"Chad Austin" <chad at> wrote in message 
news:46CA0EFE.6020103 at
|| try:
| result = yield chatGateway.checkForInvite({'userId': userId})
|'checkForInvite2 returned %s', result)

would not
except GeneratorExit: <do whatever>
solve your problem?

| except Exception:

Such catchalls are known to be prone to catch too much
and are therefore not encouraged ;-).
As in 'use at your own risk'.
Guido encourages specific catches just for the reasons you give here.

| logger.exception('checkForInvite2 failed')
| result = None
| # ...
| yield Sleep(10)
| This is real code that I wrote in the last week.  The key portion is the
| try: except:  Basically, there are many reasons the checkForInvite2 call
| can fail.  Maybe a socket.error (connection timeout), maybe some kind of
| httplib error, maybe an xmlrpclib.ProtocolError...  I actually don't
| care how it fails.  If it fails at all, then sleep for a while and try
| again.  All fine and good.
| So, my proposal is that GeneratorExit derive from BaseException instead
| of Exception.
| p.s. Should I have sent this mail to python-dev directly?  Does what I'm
| saying make sense?  Does this kind of thing need a PEP?

There was a *long* discussion of the current 2.5 exception hierarchy on 
pydev.  Search either's or gmane's archive if you want to pursue 
this.  But I expect the people involved would say much the same as above.

Terry Jan Reedy

More information about the Python-list mailing list