Friday, September 11, 2015

Exceptions: try,catch and finally in Python

# A finally block is ALWAYS run, even if you return before it

def getkids():
        try:
                val = int(raw_input("how many kids have you? "))
        except StandardError, e:
                print "Error - ",e
                return "yer wot?"
        finally:
                print "T time"
        print val
        return val

getkids()
getkids()
getkids()

No comments:

Post a Comment