Bare except clause in respect to self.DestinationURL()
Hello Zopistas! This pattern here is very common in many people's Zope products: try: u=self.DestinationURL() except: u=REQUEST['URL1'] It's usually in the manage_addXY() method, when all the work is done, we test for REQUEST!=None and we want to know where to redirect to. Is there a reason for that bare except here? Wouldn't except AttributeError: ... do the job just as well? Currently I'm in the process of smoking out bare except clauses in the Zwiki code. I've learned that bare except clauses are bad (amongst other reasons mainly because they can swallow ConflictErrors), so I try to be a good kid and get rid of them. This spot seems to be somewhere where a ConflictError could happen (we're creating something), but OTOH it gets run when creating from the ZMI, so... It might be that in this spot it's just irrelevant and I've turned pedantic in my hunt - or there might be a reason for this. What do you think? Regards, Sascha PS. I hope this doesn't kick off a bike shed discussion... :-)
--On 13. Oktober 2007 21:30:05 +0200 Sascha Welter <zopelist@betabug.ch> wrote:
Hello Zopistas!
This pattern here is very common in many people's Zope products:
try: u=self.DestinationURL() except: u=REQUEST['URL1']
All those people should burn ...
It's usually in the manage_addXY() method, when all the work is done, we test for REQUEST!=None and we want to know where to redirect to.
Is there a reason for that bare except here? Wouldn't except AttributeError: ... do the job just as well?
Basically yes - unless the method being called might raise other errors as well. -aj
participants (2)
-
Andreas Jung -
Sascha Welter