Added exception handling in preprocessing.py.