exception handing

Mark McEahern marklists at mceahern.com
Sat Jun 29 18:00:30 CEST 2002


> >>> ex1 = "spam"
> >>> try:
> ...    raise ex1
> ... except ex1:
> ...    print 'got it'

The problem is that you are using strings as exceptions--that is
discouraged.  Instead, raise a built-in exception or subclass the Exception
object.

class ex1(Exception):pass
class ex2(ex1):pass

try:
	raise ex2("some ex2 error")
except ex1, e:
	print e

// m

-






More information about the Python-list mailing list