Creating New ExceptionsNew exceptions are defined as classes
class NetworkError(Exception):
def __init__(self,args=None):
self.args = args
# Raise a user defined exception
def lookup(name):
...
raise NetworkError, "Bad hostname"
# Catch a user defined exception
try:
statements
except NetworkError, e:
print e.args
|
| <<< | O'Reilly OSCON 2000, Introduction to Python, Slide 75 July 17, 2000, beazley@cs.uchicago.edu |
>>> |