Re: Should I always call PyErr_Clear() when an exception occurs?

2004-12-21 Thread Fredrik Lundh
Jaime Wyant wrote: > What exactly "happens" if I leave the exception hanging out there? the user of your code will most likely get spurious exceptions raised in odd locations (many python operations assume that the exception state is cleared when you call them, and check the status afterwards) i

Re: Should I always call PyErr_Clear() when an exception occurs?

2004-12-21 Thread Jaime Wyant
On Tue, 21 Dec 2004 01:17:52 -0500, Tim Peters <[EMAIL PROTECTED]> wrote: > [Jaime Wyant] > > I've found that the code below will crash if I don't have the > > PyErr_Clear() function call. Should I always call PyErr_Clear()? > > That's not the right approach. Nearly all Python C API calls can >

Re: Should I always call PyErr_Clear() when an exception occurs?

2004-12-21 Thread Timo Virkkala
Nick Coghlan wrote: Although coding in C when you have the Python API to lean on is a hell of a lot better than just coding in C. . . I've lately been coding in C for a Unix programming course in our Univ. Although I've run into many interesting problems, I feel that making the same programs in

Re: Should I always call PyErr_Clear() when an exception occurs?

2004-12-21 Thread Nick Coghlan
Tim Peters wrote: Note that the Python implementation itself uses the Python C API heavily, in its C files. You can study those to get many examples of best practice. It will help to remember that coding in C isn't supposed to fun <0.9 wink>. That's right. Coding in C is supposed to remind you wh

Re: Should I always call PyErr_Clear() when an exception occurs?

2004-12-20 Thread Tim Peters
[Jaime Wyant] > I've found that the code below will crash if I don't have the > PyErr_Clear() function call. Should I always call PyErr_Clear()? That's not the right approach. Nearly all Python C API calls can fail. They return a special value if they do, primarily NULL for a call that returns

Should I always call PyErr_Clear() when an exception occurs?

2004-12-20 Thread Jaime Wyant
I've found that the code below will crash if I don't have the PyErr_Clear() function call. Should I always call PyErr_Clear()? The error message I get has to do with garbage collection --> Exception exceptions.ImportError: 'No module named badmodule' in 'garbage collec tion' ignored Fatal Python