Exceptions

Mark McEahern marklists at mceahern.com
Sat Feb 1 16:16:45 CET 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