Exceptions in 'siped' C++ code. ( Was: [PyKDE] Bug khtml.No

Jim Bublitz jbublitz at nwinternet.com
Sat Apr 19 19:01:00 BST 2003


On 19-Apr-03 Mateusz Korniak wrote:
> Thanks a lot for your answer, Jim
 
> On Saturday 19 of April 2003 00:13, Jim Bublitz wrote:
>> (...)
>> Here's the underlying C++ code:

>> Node Node::parentNode() const
>> {
>>     if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
>>     return impl->parentNode();
>> }
>>
>> bool Node::isNull() const
>> {
>>     return (impl == 0);
>> }
>>
>> Since isNull() returns 1 just before the crash, it's safe to say
>> impl == 0. When that's true, parentNode() throws a C++ exception
>> which *doesn't* propagate into Python, and the crash happens.
 
> I see.  But not always one is able to predict (and fullfil)
> conditions when C++ code runs wihout raising any exceptions.

> 1. Is there any way to get known if such exception was raised ?

I don't think so. 

> 2. What is returned as function return value when exception is
> raised ?

Since PyQt/PyKDE are normally compiled with -fno-exceptions, I'm
guessing the exception stuff effectively becomes "no-ops". but I'm
really not sure, and the g++ man page wasn't any help. That would
mean C++ is dereferencing a NULL pointer in this case, so there
wouldn't be a return value. It should be possible to install a SIG
handler, but I don't think there's a lot more you can do except try
to detect the exception conditions in your Python code before C++
sees them. In practice I don't think this will be a problem most of
the time, but I could see it being a problem once in a while.

> 3. Why C++ exceptions are not propagated to Python space ? (I
> suspect is difficult in programming sense ?)

I believe that's the answer. I'd only be guessing at the details
(it's a long time since I looked at how C++ exceptions are actually
implemented), but I suspect the C++ and Python mechanisms are hard
or impossible to get to work together reliably.
 
> I have tried to reach some info about it but failed :/

Same here.

Phil would have the definitive answers - if he's not following the
thread and doesn't answer, perhaps you might post the question as a
new thread in a day or so.

Jim
 




More information about the PyQt mailing list