Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.mixmin.net!hq-usenetpeers.eweka.nl!81.171.88.15.MISMATCH!eweka.nl!lightspeed.eweka.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'ignored': 0.05; 'except:': 0.07; 'exception.': 0.07; 'executed': 0.07; 'null,': 0.07; 'raised': 0.07; 'try:': 0.07; 'undefined': 0.07; 'python': 0.09; 'block.': 0.09; 'subject:()': 0.09; 'subject:module': 0.09; 'subject:setting': 0.09; 'throws': 0.09; 'subject:error': 0.11; 'extension': 0.13; 'behaviour.': 0.16; 'from:addr:timgolden.me.uk': 0.16; 'from:name:tim golden': 0.16; 'message-id:@timgolden.me.uk': 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; 'wrote:': 0.17; '(or': 0.18; 'module': 0.19; "python's": 0.23; 'statement': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'execution': 0.27; "doesn't": 0.28; 'noticed': 0.28; 'function': 0.30; 'code': 0.31; 'point': 0.31; 'goes': 0.33; 'null': 0.33; 'received:192.168.100': 0.33; 'to:addr:python-list': 0.33; 'code:': 0.33; 'version': 0.34; 'false': 0.35; 'add': 0.36; 'except': 0.36; 'but': 0.36; 'anything': 0.36; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; "you've": 0.61; 'leaving': 0.62; 'different': 0.63; 'behavior': 0.64; 'from:addr:mail': 0.71; 'sounds': 0.71; 'state.': 0.71; 'different.': 0.84; 'presumably': 0.84 Date: Thu, 02 Aug 2012 11:45:47 +0100 From: Tim Golden 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: In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1343904351 news.xs4all.nl 6960 [2001:888:2000:d::a6]:53608 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26396 On 02/08/2012 10:50, rahul wrote: > When I use same code base for Python 3.x, then behavior is different. In this when I return false then also it throws exception but only when any other statement get executed after this > > like below code: > ... > ... > b = None > try: > a = testModule.check(None) > except: > b = sys.exc_info() > then code execution doesn't come to except block. > But when I add one statement after calling check function then code execution goes into except block. > > ... > ... > b = None > try: > a = testModule.check(None) > print( a ) > except: > b = sys.exc_info() Sounds like you're entering into undefined behaviour. If you set an exception and don't return NULL, you're leaving Python's internals in an inconsistent state. I don't know the internal code paths, but presumably in one version it just ignored the exception state while in the other it noticed it but in a different point in the code at which point it raised the exception. Or something. Long-and-short: return NULL from an extension module function once you've raised (or are cascading) an exception condition. Anything else is undefined unless you know *exactly* what you're doing. TJG