[Zope-dev] urgent: string exceptions

Guido van Rossum guido@python.org
Fri, 11 Apr 2003 10:04:04 -0400


> You can catch most string exceptions.  "Bad Request" cannot be caught
> because (afaik) the string isn't interned because it has a space in it.

You're skating on thin ice there, mate!  This is an accident of the
implementation.

> As a workaround, I'd use except: then do
> 
> try:
>    something
> except:
>    e = sys.exc_info()
>    if e[0] == 'Bad Request':
>       do something
>    raise

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

--Guido van Rossum (home page: http://www.python.org/~guido/)