Python Tutorial

Monday, February 18, 2013

Python exceptions



All source code available on github

try:
    v = 1/0
except ZeroDivisionError:
    print "Divide by zero"

try:
    v = "CSE"
    int(v)
except ValueError:
    print "Value error"

try:
    raise Exception("Exception info")
except Exception as data:
    print data.args


Output:
Divide by zero
Value error
('Exception info',)

0 comments:

Post a Comment