I am using Python 2.7.
Based on the document ZipFile.open, I am not able to find which exception should be caught when we call the ZipFile.open.
try:
with zipfile.ZipFile(zip_file_name, "r") as f_handle:
for data_file_name in f_handle.namelist():
try:
with f_handle.open(data_file_name, "rU") as file_obj:
pass
except (RuntimeError), e:
pass
except (zipfile.BadZipfile, zipfile.LargeZipFile), e:
pass
Do you need to catch exceptions at all? Your code shows catching
RuntimeError: what will you do if that exception is raised? Generally, the best thing is to not catch exceptions unless you know what you might do about them.