PyErr_SetString() != raise ?

Discussion in 'Python' started by David Eger, Jul 15, 2003.

  1. David Eger

    David Eger Guest

    When I use PyErr_SetString() in an extension, python just keeps on
    chugging instead of acting as though a Python exception had been
    'raise'd. Why is this, and do I really have to write the Python code
    to raise an exception manually after I've used PyErr_SetString()?

    Most recently, writing an iterator -- I write:

    if (nextEl == NULL) {
    PyErr_SetString(PyExc_StopIteration, "Array index out of bounds");
    return NULL;
    }

    in my iterator extension, but when I use my extension, I get an infinite loop:

    eger@rosencrantz:/usr/src/CIM-stuff/wbemcli/bugs$ python2.2
    Python 2.2.2 (#1, Mar 21 2003, 23:40:29)
    [GCC 3.2.3 20030316 (Debian prerelease)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import StopIterTest
    >>> a = StopIterTest.dupstring("Amanda's")
    >>> b = StopIterTest.dupstring("got")
    >>> l = StopIterTest.stringArray()
    >>> l.add(a)
    >>> l.add(b)
    >>> for i in l:

    .... print i
    ....
    _10180840_p_string
    _10181b38_p_string
    None
    None
    None
    None
    None
    None
    None
    None
    None
    None

    (and so on, and so on...) The thing is, even though I *set* the
    exception with PyErr_SetString, to the interpreter, it doesn't get
    raised. Am I just misinterpretting how PyErr_SetString is supposed
    to work?

    -David
    David Eger, Jul 15, 2003
    #1
    1. Advertising

  2. David Eger wrote:
    :> My exception disappears!

    to which Paul Simmonds <> replied:
    : This part should work fine. Try looking back through the function
    : calls, layer by layer, making sure each function in turn tests for a
    : NULL return, and propagates it back to the interpreter. Without a
    : little more code it's tough to say exactly what's wrong.

    I've found the place where my exception gets swallowed. Thanks for the
    pointer! The problem is in the SWIG wrappers: I'm taking discussion
    to that list: .

    -Eger David
    Modular Forms Boy, Jul 15, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jacol

    raise or not to raise [Newbie]

    Jacol, Feb 3, 2007, in forum: Python
    Replies:
    5
    Views:
    402
    Gabriel Genellina
    Feb 5, 2007
  2. ernest
    Replies:
    2
    Views:
    286
    Roy Smith
    Nov 14, 2010
  3. Jack Bates
    Replies:
    0
    Views:
    276
    Jack Bates
    May 2, 2011
  4. bvdp

    Raise X or Raise X()?

    bvdp, Mar 11, 2012, in forum: Python
    Replies:
    10
    Views:
    361
    Stefan Behnel
    Mar 12, 2012
  5. rahul
    Replies:
    8
    Views:
    400
    Stefan Behnel
    Aug 2, 2012
Loading...

Share This Page