[Zope-dev] "Bad Request" exception / string; was: urgent: string exceptions

Clemens Robbenhaar zope-dev@zope.org
Fri, 11 Apr 2003 16:28:10 +0200


Guido van Rossum writes:
 [...]
 > Why is there code writing
 > 
 >   raise 'Bad Request'
 > 
 > That code should be fixed!  It ought to use a class exception; if
 > that's not possible, it ought to at least give the string a global
 > name, like so:
 > 
 > BadRequest = 'Bad Request'
 > 
 >   .
 >   .
 >   .
 >   raise BadRequest
 [...]

 The verbatim raise 'BadRequest' is used in ca 40 places in the current
zope sources (as 2.6.1, HEAD may differ).

 However for the problem at hand, the approach is actually quite like
the proposed named string  (OFS/ObjectManager, around line 47; ist
named a bit different:

BadRequestException = 'Bad Request'



 It seems this actually may cause the problem, because this
module variable BadRequest is maybe equal, but not the same as bare 
string "Bad Request" (wild guess of mine) ?


 Unfortunately the exception string module variable cannt be imported
from a python script, as not even OFS.ObjectManager is allowed in a
python script. (for some good reason, I guess.)


 If thinking about improving the current implementation: maybe the
BadRequest exception should be defined in some central place, where
comon exceptions are defined? e.g. in the zExceptions module (do not
know if this is actually intended to be used as a central exception
pool...)


Chris McDonough writes:
 > That'd be fine, but it would require a code audit.  And third party
 > products might fail.

Er, yes, they may. Possibly it would help them, if they know the
exception is defined in one place, and all they have to do is to revert
the exception class to a string?

just my 2 cents,
clemens