I have a method which accepts a filename as a parameter, all filenames should end with ‘.csv’. Which exception should I throw if a filename that does not end with .csv is passed?
Or should I take a different approach?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
ArgumentOutOfRangeException – What you’re describing is in line with an out of range exception:
ArgumentException is used to validate the characters in the path string not the file type.
IMHO the path validation fall-through chart looks like this:
ArgumentNullException
ArgumentException
FileNotFoundException
ArgumentOutOfRangeException
UnauthorizedAccessException
operation = NotSupportedException
If that’s not descriptive enough for you then create your own exception class:
…