Re: [Zope-dev] Greedy except clauses
ooo. Richard didn't do it right - there's actually over _600_ bareword except: clauses in the current zope-2_3-branch A quick breakdown of some of the biggies: 71 in OFS/ 61 in ZODB/ 56 in ZServer/ 53 in ZGadflyDA 50 or so in what seems to be test scripts or modules (probably ok) 42 in ZPublisher/ 42 in DocumentTemplate/ 40 in App/ 38 in AccessControl/ 32 in Shared/DC/ZRDB/ 24 in ZCatalog 15 in webdav/ 15 in DateTime/ 13 in PythonScripts 12 in utilities/ or the install scripts 11 in OFSP/ Now, it's obvious that not all of these are bad - some are probably fine - but there's also many that are _not_ good. The one in MailHost.py does eat exceptions. I'm sure there are others. I've done a quickie hack script that runs over the source and produces a list of matches to lines in the file, and links to a lightly patched viewcvs so that you can jump straight to the lines. It seems like it would be reasonably easy to make this a bit more sophisticated to include things like the nesting 'def' and 'class' method. This, to me, seems like a pretty nice community type task - people could take one of them off the list of unchecked ones, and have a look through the code... no? Anthony
"AB" == Anthony Baxter <anthony@interlink.com.au> writes:
AB> Now, it's obvious that not all of these are bad - some are AB> probably fine - but there's also many that are _not_ good. The AB> one in MailHost.py does eat exceptions. I'm sure there are AB> others. I am probably a bit idiosyncratic, but I prefer to avoid bare excepts at all costs. I often use "except Exception:", otherwise I add a comment that specifically notes that I intend to catch everything. Otherwise, you can't tell the difference between intentional and accidental use. AB> I've done a quickie hack script that runs over the source and AB> produces a list of matches to lines in the file, and links to a AB> lightly patched viewcvs so that you can jump straight to the AB> lines. It seems like it would be reasonably easy to make this a AB> bit more sophisticated to include things like the nesting 'def' AB> and 'class' method. AB> This, to me, seems like a pretty nice community type task - AB> people could take one of them off the list of unchecked ones, AB> and have a look through the code... no? It would also be interesting to see how many try/except blocks are including more code than they should. The larger the block, the more likely that a line of code raises an error that the author didn't consider; these errors can mean that real bugs get caught be accident and ignore. When the block is small -- preferably just a line or two -- there is litle chance for error. Of course, there are very good reasons to have longer except blocks. Jeremy
Jeremy Hylton wrote:
I am probably a bit idiosyncratic, but I prefer to avoid bare excepts at all costs. I often use "except Exception:", otherwise I add a
Will that catch string exceptions? eg: raise 'Something bad happened' If not, then it's not much use in Zope, which is unfortunately riddled with String exceptions :-S cheers, Chris
"CW" == Chris Withers <chrisw@nipltd.com> writes:
I am probably a bit idiosyncratic, but I prefer to avoid bare excepts at all costs. I often use "except Exception:", otherwise I add a
CW> Will that catch string exceptions? eg: raise 'Something bad CW> happened' No. CW> If not, then it's not much use in Zope, which is unfortunately CW> riddled with String exceptions :-S That might be something worth fixing, too. :-) Jeremy
participants (3)
-
Anthony Baxter -
Chris Withers -
Jeremy Hylton