Python Exception in Thread
Master Python with 70+ Hands-on Projects and Get Job-ready - Learn Python
Program 1
import time
from threading import *
#Exception in Thread
# def display(a,b):
# print("This is my display Thread")
# c=a//b # threading.excepthook()
# # Main Thread
# T1=Thread(target=display,args=(20,5))
# T1.start()
# a=int(input("Enter First Number"))
# b=int(input("Enter First Number"))
# c=a//b # sys.excepthook()
# print(c)
# c=a+b
# print(c)
# c=a-b
# print(c)
def display():
try:
print("This is my display Thread")
print(15//0)
except Exception as obj:
print("Unable to divide by zero")
def show(n):
print("This is my show Thread")
for i in range(1,11):
print(n*i)
time.sleep(1)
#Main Thread
T1=Thread(target=display)
T2=Thread(target=show, args=(8,))
T1.start()
T2.start()
Did you like our efforts? If Yes, please give DataFlair 5 Stars on Google

