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, ValueError
– Eduard Aug 10 '16 at 10:40def check_file(file): try ... except your_ exceptions_here ...
– Eduard Aug 10 '16 at 10:44try: read_file
then you could go withexcept FileNotFound? ... except IsNotAFile? ...
.. but if your doingtry: read_file then crunch it
then yea, segregate them. – Eduard Aug 10 '16 at 10:46