[Python-Dev] Deprecating string exceptions

Barry A. Warsaw barry@zope.com
Wed, 27 Mar 2002 23:31:40 -0500


>>>>> "SM" == Skip Montanaro <skip@pobox.com> writes:

    SM> Taking a quick peek at my own code, the only place I see that
    SM> strings are raised is in code that works with ZServer
    SM> (e.g. "raise 'redirect'").
---------------^^^^^^^^^^^^^^^

That's kind of scary Skip!  I.e. I belive the following is /not/
guaranteed to work in any version of Python that I'm aware of:

    try:
	raise 'foo'
    except 'foo':
	print 'foo caught'

because 'foo' is not (necessarily) 'foo'.

Much better to use:

    FOOEXC = 'foo'
    try:
	raise FOOEXC
    except FOOEXC:
	print 'foo caught'

-Barry