Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #26385

Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString()

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <mail@timgolden.me.uk>
X-Original-To Python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'exception': 0.03; 'args)': 0.07; 'false.': 0.07; 'null,': 0.07; 'api': 0.09; 'expected.': 0.09; 'here?': 0.09; 'subject:()': 0.09; 'subject:module': 0.09; 'subject:setting': 0.09; 'throw': 0.09; 'throws': 0.09; 'tuple.': 0.09; 'subject:error': 0.11; 'extension': 0.13; 'static': 0.13; '(null,': 0.16; 'from:addr:timgolden.me.uk': 0.16; 'from:name:tim golden': 0.16; 'message-id:@timgolden.me.uk': 0.16; "module's": 0.16; 'null.': 0.16; 'pyobject*': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'subject: \n ': 0.16; 'subject:exception': 0.16; 'subject:through': 0.16; 'tjg': 0.16; 'url:py3k': 0.16; 'wrote:': 0.17; 'implementing': 0.17; 'module,': 0.17; 'input': 0.18; 'skip:p 30': 0.20; 'doc': 0.22; 'null)': 0.22; 'null;': 0.22; 'idea': 0.24; 'tried': 0.25; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'looks': 0.26; 'appreciated.': 0.26; "doesn't": 0.28; 'skip:( 20': 0.28; 'piece': 0.29; 'function': 0.30; 'error': 0.30; 'url:python': 0.32; 'like:': 0.33; 'null': 0.33; 'received:192.168.100': 0.33; 'to:addr:python-list': 0.33; 'false': 0.35; 'returning': 0.35; 'but': 0.36; 'url:org': 0.36; 'should': 0.36; 'correctly': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'help': 0.40; 'think': 0.40; 'first': 0.61; 'from:addr:mail': 0.71; 'saw': 0.75; '.....': 0.75; 'happening?': 0.84; 'indicator': 0.91
Date Thu, 02 Aug 2012 10:06:29 +0100
From Tim Golden <mail@timgolden.me.uk>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20120713 Thunderbird/14.0
MIME-Version 1.0
To Python-list@python.org
Subject Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString()
References <fa944ed7-8101-4b2f-a49a-363eb8d05d1d@googlegroups.com>
In-Reply-To <fa944ed7-8101-4b2f-a49a-363eb8d05d1d@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2856.1343898392.4697.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1343898392 news.xs4all.nl 6857 [2001:888:2000:d::a6]:42002
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:26385

Show key headers only | View raw


On 02/08/2012 09:57, rahul wrote:
> I am implementing a C extension module, during this I saw that when I
> set the global error indicator and error message through
> PyErr_SetString() API and return false.
> 
> But it doesn't throw any error when I tried to check the error
> through sys.exc_info() then it returns (NULL, NULL, NULL) tuple.
> 
> When I return NULL through the C extension module's function then it
> works correctly and throws the exception as expected.
> 
> The skeleton looks like:
> 
> static PyObject* check(PyObject* sef, PyObject* args) { PyObject*
> input = NULL; if (!PyArg_ParseTuple(args, "O", &input)){ return
> NULL; } ..... ..... PyErr_SetString(PyExc_Exception, "Throwing Error
> through check function"); Py_RETURN_FALSE; }
> 
> Any idea on why this is happening? Any help will be appreciated.


Because you're returning False. You should be returning NULL. Which is
why it works when you do :)

Have a look at the first line of this page:

http://docs.python.org/py3k/extending/extending.html#intermezzo-errors-and-exceptions


Which piece of documentation led you to think that returning False was
the thing to do here? Perhaps there's a doc that needs fixing?


TJG

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

C extension module doesn't throw exception after setting error indicator through PyErr_SetString() rahul <rahul03535@gmail.com> - 2012-08-02 01:57 -0700
  Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() Tim Golden <mail@timgolden.me.uk> - 2012-08-02 10:06 +0100
    Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() rahul <rahul03535@gmail.com> - 2012-08-02 02:21 -0700
    Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() rahul <rahul03535@gmail.com> - 2012-08-02 02:21 -0700
      Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() Tim Golden <mail@timgolden.me.uk> - 2012-08-02 10:37 +0100
        Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() rahul <rahul03535@gmail.com> - 2012-08-02 02:50 -0700
          Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() Tim Golden <mail@timgolden.me.uk> - 2012-08-02 11:45 +0100
          Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() Stefan Behnel <stefan_ml@behnel.de> - 2012-08-02 12:54 +0200
        Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() rahul <rahul03535@gmail.com> - 2012-08-02 02:50 -0700

csiph-web