Exceptions

Mark McEahern marklists at mceahern.com
Sat Feb 1 10:16:45 EST 2003


[Tetsuo]
> I can't figure out how to do a custom error definition so the Try-Except
> thing would work. Could someone put it simply?

Subclass your exception from Exception; e.g.,

class MyException(Exception):pass

def dostuff():
    raise MyException

try:
    dostuff()
except MyException, e:
    print "We caught %s" % e

// m
-






More information about the Python-list mailing list