Catch exception throwed inside a function : Catch Exceptions : Language Basics PYTHON examples


PYTHON examples » Language Basics » Catch Exceptions »

 

Catch exception throwed inside a function


Catch exception throwed inside a function


def f():
    print "in f, before 1/0"
    1/0                           # raises a ZeroDivisionError exception
    print "in f, after 1/0"

def g():
    print "in g, before f()"
    f()
    print "in g, after f()"

def h():
    print "in h, before g()"


try:
    g()
    print "in h, after g()"
except ZeroDivisionError:
    print "ZD exception caught"
print "function h ends"

           
       



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON examples

 Navioo Language Basics
» Catch Exceptions