I'm writing a parser for a certain file format. If a file is not correctly formatted (and can not be parsed) then the parser throws an exception.
What exception class, in the Python 2 exception hierarchy, should I use?
However, a FormatException exception that is thrown when you're trying to parse a predefined or hard-coded string indicates a program error.
ParseException . This is a checked exception an it can occur when you fail to parse a String that is ought to have a special format. One very significant example on that is when you are trying to parse a String to a Date Object. As you might know, that string should have a specified format.
How do I fix parsing errors? Easily: read a traceback message, rewrite your code accordingly, and re-run the program again. That's one of the reasons why Python is so awesome! It tells you what's wrong with your code in traceback messages so all you have to do is learn to read those messages.
Files are identified locations on a disk where associated data is stored. Working with files will make your programs fast when analyzing masses of data. Exceptions are special objects that any programming language uses to manage errors that occur when a program is running.
ValueError
seems to be appropriate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With