Exception design: Custom exceptions reading data from file?

Posted by User on Stack Overflow See other posts from Stack Overflow or by User
Published on 2010-03-31T03:20:18Z Indexed on 2010/03/31 3:23 UTC
Read the original article Hit count: 374

I have a method that reads data from a comma separated text file and constructs a list of entity objects, let's say customers.

So it reads for example,

Name
Age
Weight

Then I take these data objects and pass them to a business layer that saves them to a database. Now the data in this file might be invalid, so I'm trying to figure out the best error handling design. For example, the text file might have character data in the Age field.

Now my question is, should I throw an exception such as InvalidAgeException from the method reading the file data? And suppose there is length restriction on the Name field, so if the length is greater than max characters do I throw a NameTooLongException or just an InvalidNameException, or do I just accept it and wait until the business layer gets a hold of it and throw exceptions from there?

(If you can point me to a good resource that would be good too)

© Stack Overflow or respective owner

Related posts about c#

Related posts about exception