I'm a Python learner, trying to handle a few scenarios:
- Reading a file.
- Formatting Data.
- Manipulating/Copying Data.
- Writing a file.
So far, I have:
try:
# Do all
except Exception as err1:
print err1
#File Reading error/ File Not Present
except Exception as err2:
print err2
# Data Format is incorrect
except Exception as err3:
print err3
# Copying Issue
except Exception as err4:
print err4
# Permission denied for writing
The idea of implementing in this fashion is to catch the exact error for all different scenarios. I can do it in all separate try/except blocks.
Is this possible? And reasonable?
except KeyError, ValueErrordef check_file(file): try ... except your_ exceptions_here ...try: read_filethen you could go withexcept FileNotFound? ... except IsNotAFile? ..... but if your doingtry: read_file then crunch itthen yea, segregate them.