[FRPythoneers] trapping exceptions

Erick Bodine erick at allocity.com
Wed May 21 11:08:47 MDT 2003


All,

I would like to create a custom exception class that would wrap IOError
so that I can catch its message string and do some other things.  I made
a stab at it with the below code, trying several variations none of
which were successful.  How is this accomplished and is there a better
way?

class MyException(IOError):
	def __init__(self):
		change_state(0)

def change_state(value):
	# change a value in a temp file

try:
	f = open('nonexistent.txt')
except MyException, error:
	print "IOError message"

--ERick



More information about the FRPythoneers mailing list