c# - What exception should I throw for a failed file parsing? -
i have method parsing file. however, parsing fail anytime, depending on various conditions (not-so-cautious user playing file, example).
public string parsedatfile(string datfile) { string[] deezlines = file.readalllines(datfile); // we're searching essential info within file. bool daessentialdatafound = false; foreach (string datline in deezlines) { if (datline.contains("daessentialdata")) { daessentialdatafound = true; break; } } if (!daessentialdatafound) throw new whatshouldithrowexception("yo dood where's da essential info in " + datfile + "?"); dostuffwith(deezlines); }
is there exception utilize in such scenario? thought about:
formatexception: not clear issue, custom exception: not have special treatment exception i'm throwing, i'd rather avoid using custom exception, though that's way settle things down.
fileformatexception should fine :
the exception thrown when input file or info stream supposed conform file format specification malformed.
you can optionally provide uri , descriptive error message.
if don't want reference windowsbase
may create own exception specific format. based on fact there xmlexception
thrown xmlreader.read
.
c# parsing exception
No comments:
Post a Comment