[Python-Dev] PyExc_UnicodeDecodeError (original) (raw)
Thomas Heller theller at python.net
Wed Sep 15 18:01:07 CEST 2004
- Previous message: [Python-Dev] PyExc_UnicodeDecodeError
- Next message: [Python-Dev] PyExc_UnicodeDecodeError
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"M.-A. Lemburg" <mal at egenix.com> writes:
Thomas Heller wrote:
Can anyone explain why calling this code in a C extension static PyObject * test(PyObject *self, PyObject *arg) { PyErrSetString(PyExcUnicodeDecodeError, "blah blah"); return NULL; } PyMethodDef modulemethods[] = { {"test", test, METHNOARGS}, {NULL, NULL} }; does this (same in 2.3.4, and 2.4 current CVS):
from somewhere import test test() Traceback (most recent call last): File "", line 1, in ? TypeError: function takes exactly 5 arguments (1 given) See Python/exceptions.c: PyObject * PyUnicodeDecodeErrorCreate( const char *encoding, const char *object, int length, int start, int end, const char *reason) { return PyObjectCallFunction(PyExcUnicodeDecodeError, "ss#iis", encoding, object, length, start, end, reason); } This exception is thrown by codecs that want to signal a decoding error. It includes the context of the problem as well as the reason string.
Thanks, this makes sense. The real problem I wanted to solve is a little bit less contrieved ;-)
In this context: I find Exceptions being much too underdocumented. Not only that a lot of built in exceptions are not listed in <http://www.python.org/doc/current/api/standardExceptions.html>, also I find the description for the exceptions here <http://www.python.org/dev/doc/devel/lib/module-exceptions.html> very diffcult to understand, if you want to define a subclass of, for example, WindowsError for your own code.
A much more interesting and understandable reading is the exceptions.py module which was last used in 1.5, afaik.
I'm not sure what there can be done about that, maybe keep exceptions.py in sync (although unused) with the current code, and point to it from the docs?
Thomas
- Previous message: [Python-Dev] PyExc_UnicodeDecodeError
- Next message: [Python-Dev] PyExc_UnicodeDecodeError
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]