I have a function that tries to retrieve temperature readings from a csv file and returns a vector with Temp_reading
objects containing corresponding hour and temperature readings.
The code works fine. What I am uncertain of is if you should throw exceptions if there is a formatting error in the csv or try to recover inside the function. I am currently reading Bjarne Stroustrups principle and practice using C++ where he argues that you should always try to recover from a istream
in fail()
state or when encountering bad input in general. So lets say I try to recover from a bad csv format by for example skipping rows that contain too many columns or only reading as many columns as there is header columns. Or maybe skipping all data elements that can not be converted to doubles using std::stod
.
Wont this do more harm since I am letting the caller store data which is not identical to the contents of the data file?