Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exception class to use for file parsing error?

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?

like image 488
Johan Råde Avatar asked Feb 14 '12 12:02

Johan Råde


People also ask

Which type of exception is commonly associated with parsing errors?

However, a FormatException exception that is thrown when you're trying to parse a predefined or hard-coded string indicates a program error.

What is a parser exception?

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 you fix parsing errors in Python?

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.

What is a file exception?

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.


1 Answers

ValueError seems to be appropriate.

like image 53
Jakub Roztocil Avatar answered Oct 04 '22 11:10

Jakub Roztocil