I am loading data from text files into db tables. Data in files is sometimes corrupted at the field level (files are comma-delimited .csv files)
I read every row in an object that represents a row of data with properties that are the correct data type.
If reading from an object is not performed due to ingenious data, I want to read a string into a similar object as the first, only this one has all the data types set to a string, so reading into it should not be fal.
The idea is that I can create a set of valid record objects that I will load into the corresponding db table, and a set of exceptions that I will load into the exception table. Then they can be considered later.
So - the question is:
I'm going to iterate over the lines of a text file and load them into an object and add the object to the collection. There will be a try / catch loop, and if loading the object fails, then in the catch section I will load the exception object and add it to the exception collection.
However, what happens if the error of the exception object fails (for some reason). Do I put try / catch around this and log exceptions - e.g. try / catch in try / catch?
Is there a better way to do this?
source
share