Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'exercise': 0.04; 'exception': 0.05; 'interpreter': 0.05; 'debugging': 0.07; 'compile-time': 0.09; 'exception,': 0.09; 'exception.': 0.09; 'if,': 0.09; 'programmer': 0.11; 'defined,': 0.16; 'exceptions,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'massively': 0.16; 'plus,': 0.16; 'python;': 0.16; 'silly': 0.16; 'sorts': 0.16; 'subject:exception': 0.16; 'uncommon': 0.16; 'variables,': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'issue.': 0.20; 'detect': 0.22; 'instance,': 0.22; 'odd': 0.22; 'subject:problem': 0.22; 'trying': 0.22; 'header:In-Reply-To:1': 0.23; "i'd": 0.24; 'error.': 0.24; 'variable': 0.24; 'all.': 0.24; 'question': 0.26; 'work,': 0.26; 'message-id:@mail.gmail.com': 0.27; 'received:209.85.214.174': 0.27; 'errors': 0.27; 'have,': 0.27; 'error': 0.28; 'block,': 0.29; 'exceptions': 0.29; 'helpful.': 0.29; 'legacy': 0.29; 'run': 0.29; 'am,': 0.30; 'framework': 0.30; 'code': 0.31; '(and': 0.31; 'usually': 0.32; 'could': 0.33; 'running': 0.34; "can't": 0.34; 'received:google.com': 0.34; 'done': 0.34; 'getting': 0.35; 'server.': 0.35; 'should': 0.35; 'add': 0.35; 'received:209.85': 0.35; 'to:addr:python-list': 0.35; 'problem': 0.35; 'easier': 0.35; 'except': 0.35; 'expect': 0.35; 'that,': 0.36; 'something': 0.36; 'gives': 0.36; 'but': 0.36; 'problems': 0.37; 'subject:: ': 0.37; 'being': 0.37; 'received:209': 0.37; 'self': 0.38; 'some': 0.38; 'wanted': 0.38; "didn't": 0.39; 'to:addr:python.org': 0.39; 'why': 0.39; 'header:Received:5': 0.39; 'where': 0.40; 'time,': 0.62; 'over': 0.62; 'information': 0.62; 'remove': 0.63; 'more': 0.63; 'real': 0.63; 'here': 0.65; 'life': 0.65; 'making': 0.67; 'execution.': 0.84; 'hunt': 0.84; 'friday': 0.91; 'received:mail- ob0-f174.google.com': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=kUxZxfD49cPFcrjm8FTLVES9zqsZxlSoXvYwfaibshk=; b=a2s5MB/ahzrHZSjUT1cyW3ZKul2rUkp/1L3Z0NO0UN6LyVtuZIyN48MkuUVX/kccMR MgrlYjaAGz15oym6EG7S0YgNq+UbhJ+Gstr2YcZauikohxsfM0RaZVZ0ExafX8PAIOoQ 6b1PjHXMcQXFj2F92JxvZZzjuircmZE9RFqlSin3rkozEq0a3qF2y/0WhuPBkzIl3zA0 o4zzZUkUiBhU8riKmI2pEMxOKs0K4q8xZnHPQiCRjCFpTLgUUpPcGx75saB+TaJK8/dI syv7dCKtNQI1GdyO7CWAWriFEuW2SspidDXU3A0ZuZ/YGyK0M3zSk91DO3XQ62ksESNl gsyA== MIME-Version: 1.0 In-Reply-To: <4FE79FC9.5050404@earthlink.net> References: <4FE79433.8020704@earthlink.net> <4FE7982C.5020708@mrabarnett.plus.com> <4FE79FC9.5050404@earthlink.net> Date: Mon, 25 Jun 2012 09:51:15 +1000 Subject: Re: exception problem From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1340581879 news.xs4all.nl 6905 [2001:888:2000:d::a6]:53513 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:24407 On Mon, Jun 25, 2012 at 9:16 AM, Charles Hixson wrote: > But what I wanted was to catch any exception. =A0A problem was happening = and I > had no clue as to what it was. =A0(It turned out to be "self is not defin= ed". > =A0A silly mistake, but a real one.) > > The odd thing was that if I ran it without the try block, I didn't get an= y > exceptions at all. =A0(Which I clearly should have, except that since sel= f > wasn't defined, I'd usually expect the interpreter to detect the error > before trying to execute the code.) Python, not having any concept of declared variables, can't detect such errors prior to execution. The error isn't like in C where you're trying to use a variable that's not declared; the error is that, at run time, there's no global with the name "self". That's why it's an exception, not a compile-time error. But the real question is: Why do you get no exception traceback if you remove the try/except? Is something else swallowing everything thrown? This is something that you will need to solve. (And it's a pretty annoying issue. We had the same thing here at work, though in Javascript not Python; a framework was swallowing exceptions, so all sorts of work was being done blindfolded. Legacy code is not fun. Life got a lot easier for us last Friday when I found and excised the offending try/catch.) Hunt around and see if exceptions are getting logged someplace other than your console - not uncommon if, for instance, you're running in a web server. This is not going to be the only time when you get an exception that could be massively helpful. Mind you, I think every programmer should spend some time debugging blind. It gives you such an appreciation for interactive debuggers. Plus, it's an exercise in making your problems reproducible, if you have to start your program over every time you add some more information to it :) ChrisA