raising SyntaxError while parsing file?

Ignacio Vazquez-Abrams ignacio at openservices.net
Fri Aug 31 22:10:00 EDT 2001


On Fri, 31 Aug 2001, Roy Smith wrote:

> I've got a class which parses a data file, and I want to be able to signal
> a parse error.  Would it be appropriate to raise SyntaxError for that, or
> is SyntaxError really reserved for errors in the python code itself?

Create your own exception by creating an empty exception descended from
Exception:

---
>>> class ParseError(Exception):
...   pass
...
>>> raise ParseError, 'blah'
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
__main__.ParseError: blah
>>>
---

-- 
Ignacio Vazquez-Abrams  <ignacio at openservices.net>





More information about the Python-list mailing list