Wednesday 12 July 2017

38 assert and raise in exception handling

####
def test(a,b):
    assert a>b, "a must be big than b"
try:
    test(0,20)
except AssertionError as e:
    print (e)
'''
When it encounters an assert statement,
Python evaluates the accompanying expression, which is hopefully true.
If the expression is false, Python raises an AssertionError exception.
'''


'''
def rexp(b):
    #a=int(a)
    if(type(b)==type(2)):
        return b*b
    else:
        raise ValueError("not matching with int")
a="v"
#print(type(a))
try:
    print(rexp(a))
except ValueError as e:
    print(e)

'''
 

No comments:

Post a Comment