[pylucene-dev] can't override QueryParser.parse()

Andi Vajda vajda at osafoundation.org
Tue Nov 13 19:52:47 PST 2007


On Tue, 13 Nov 2007, Bill Janssen wrote:

> This (in functions.cpp) looks wrong.  You're creating an instance of
> ThrowableType, but saying that it's of type JavaError when you call
> PyErr_SetObject().
>
> Bill
>
> PyObject *PyErr_SetJavaError(jthrowable throwable)
> {
>    PyObject *err = t_Throwable::wrapObject(Throwable(throwable));
>
>    PyErr_SetObject(PyExc_JavaError, err);
>    Py_DECREF(err);
>
>    return NULL;
> }

No, this code gets python to raise an error of type JavaError whose
error argument is the actual java throwable instance, wrapped.

What you see is two layers of wrappers:
   1. Throwable(throwable)
      wraps a C++/JNI wrapper around the actual java throwable
   2. t_Throwable::wrapObject(...)
      wraps the CPython Throwable type around the C++/JNI wrapper so that
      one can make calls on it from python (such as getJavaException())

Once can then call getJavaException() on that JavaError instance to retrieve 
the java stack trace from the actual java throwable:

   try:
       java(blah)
   except JavaError, e:
       print e.getJavaException().printStackTrace()

Andi..


More information about the pylucene-dev mailing list