How to catch a thread's exception in the caller thread in Python?
I have the following script which copies files from one location to another.
If the files cannot be copied, an exception is thrown.
The following code does not work:
class TheThread(threading.Thread):
def __init__(self, FromFolder, ToFolder):
threading.Thread.__init__(self)
self.FromFolder = FromFolder
self.ToFolder = ToFolder
def run(self):
try:
shul.copytree(self.FromFolder, self.ToFolder)
except:
raise
try:
threadClass = TheThread(arg1, arg2,…)
threadClass.start() #Exception occurs here
except:
print "An exception is caught"
How to catch the exception?