[Python-Dev] Deprecating string exceptions

Guido van Rossum guido@python.org
Wed, 27 Mar 2002 15:56:48 -0500


> > > http://python.org/sf/518846 reports that new-style classes cannot be
> > > used as exceptions. I think it is desirable that this is fixed, but I
> > > also believe that it conflicts with string exceptions.
> > 
> > Can you explain this conflict?  Couldn't this be worked around by
> > making an exception for strings?
> 
> Currently, if you write
> 
> try:
>   raise "Hallo"
> except str:
>   pass
> 
> the exception will pass through. If "new-style classes" (aka types)
> are allowed, then the string /should/ be caught.

Gotcha.  But I could easily accept a bw compatibility rule that says
you can't have a subclass of str (that's not also a subclass of
Exception) in the except clause until string exceptions have been
removed from the language.  All of this is irrelevant though, because...

> > I think string exceptions are used enough that we should deprecate
> > them on a slower schedule.
> 
> If you follow Paul's rationale (exceptions should inherit from
> Exception), then the bug report could be closed, and no action would
> be needed until Exception becomes a type.

Fair enough; go ahead and close the bug.

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