[英]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? 我应该使用Python 2异常层次结构中的哪个异常类?
How about 怎么样
class XyzParseError(Exception):
pass
where XyzParser
is the name of your parser class? XyzParser
在XyzParser
是您的解析器类的名称? That's also what HTMLParser
in the standard library does. 这也是标准库中的
HTMLParser
所做的。
ValueError
似乎是适当的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.