Exception Handling Examples In Python3

1. Simple Example To Show The Use Of try and except blocks in python3.

try:
    #open("dd.txt","r")
    a=10
    b='e'
    c=a/b
    print(c)
except ZeroDivisionError:
    print("ZeroDivisionError Occured")
except TypeError:
    print("TypeError Occured")
except Exception:
    print("Some Error Occurred")

2. Simple Example To Show The Use Of try,except and finally blocks in python3.

try:
    a=10
    b=0
    c=a/b
    print(c)
except ZeroDivisionError:
    print("Exception Occured")
finally:
    print("End Of The Program")

3. Simple Example To Show The Use Of assert in python3.

def multiplication(a,b):
    assert(a!=0),"Can't Perform Multiplication"
    assert(b!=0),"Can't Perform Multiplication"
    return(a*b)


print(multiplication(2,3))
#print(multiplication(0,3))
print(multiplication(3,0))