c# - Choosing between exception and return value -


I have created a class that parse some documents from the file.

Parser {public parse (string filename) {/}}

In that situation, sometimes parsing errors in that situation Some special data has to be returned. I have created a special class for this

  class ParsingError {// some data}   

How can I handle this kind of errors correctly? There are at least two options:

Revert your own exception or price.

Option A

  myParser Parse (filename, error outside);   

Option two

  try {myParser.Parse (fileName)} hold (MyParsingException ex) {// Usage error Field}   

UPDATE

If I do not wrong the ideology behind the exception, then this extraordinary thing should be tackled, it is such a situation which is not the law < / P>

This would be of the opinion that for example:

Finds unknown fields in the Parser file, or the encoding is incorrect

Think of how normal it is to have a parsing error if it is normal - a return value of Favors should be used for an exception which is not normal.

Comments