[Python-Dev] why string exceptions are bad

Barry Warsaw barry at python.org
Fri Mar 19 17:41:54 EST 2004


On Fri, 2004-03-19 at 17:30, Jewett, Jim J wrote:

> A class can be defined in a single place (and imported); 
> a typo in the 47th raise statement will show up as a syntax
> error instead of a runtime bug.

Yes, but I'll just note that this is "safe":

foo.py
------
Error = 'Bogus Error'

def foo():
	...
	raise Error


bar.py
------
import foo

try:
	foo.foo()
except foo.Error:
	# oops!


That works because you're raising and catching the same object.  String
exceptions still suck though. :)

-Barry





More information about the Python-Dev mailing list