tags:

views:

51

answers:

3

I parse an XML file to load data, and when i have an attribute that has an unrecognized value, i throw an InvalidDataException. Is this the correct one or is there a better/more descriptive one

+3  A: 

That seems reasonable to me. It's not an exception I'm particularly familiar with (i.e. I haven't come across it in other APIs) but it gets the point across.

I guess the only question is whether an IOException of some form would be more appropriate. It's not the actual transfer that's the problem here, of course - it's the content that's being transferred. It's a grey area, certainly.

Jon Skeet
+2  A: 

That exception suggests that it's an error in the format of the file itself, like an error in the encoding of the characters. An XmlException would be a better fit.

Consider throwing an ApplicationException instead, as it's not really an error in the XML format, but rather something that the XML contains that your application does not accept.

Guffa
Youre probably right. Thanks!
RCIX
A: 

If you have a published schema, maybe a SchemaValidationException will be appropriate.

Kousik Nandy
Nope no schema (yet).
RCIX