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


Groups > comp.lang.python > #24406

Re: exception problem

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!204.52.135.9.MISMATCH!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <charleshixsn@earthlink.net>
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.05; 'interpreter': 0.05; 'mrab': 0.05; 'finally:': 0.07; 'none:': 0.07; '(self,': 0.09; 'except:': 0.09; 'exception.': 0.09; 'try:': 0.09; 'def': 0.11; '(it': 0.16; 'chunks': 0.16; 'code?': 0.16; 'defined,': 0.16; 'exist.': 0.16; 'line)': 0.16; 'message- id:@earthlink.net': 0.16; 'received:dsl.mindspring.com': 0.16; 'silly': 0.16; 'str)': 0.16; 'subject:exception': 0.16; 'wrote:': 0.17; 'detect': 0.22; 'odd': 0.22; 'subject:problem': 0.22; 'trying': 0.22; 'header:In-Reply-To:1': 0.23; "i'd": 0.24; 'all.': 0.24; 'print': 0.25; 'header:User-Agent:1': 0.26; '(which': 0.26; 'have,': 0.27; 'error': 0.28; "doesn't": 0.28; 'assert': 0.29; 'block,': 0.29; 'exceptions': 0.29; 'produces': 0.29; 'code:': 0.29; 'skip:( 20': 0.30; 'skip:_ 10': 0.31; 'usually': 0.32; 'could': 0.33; 'should': 0.35; 'to:addr:python-list': 0.35; 'problem': 0.35; 'except': 0.35; 'expect': 0.35; 'but': 0.36; 'subject:: ': 0.37; 'self': 0.38; 'received:66': 0.38; 'pm,': 0.38; 'end': 0.38; 'wanted': 0.38; "didn't": 0.39; 'to:addr:python.org': 0.39; 'real': 0.63; 'finally': 0.67; '3...': 0.84; 'bare': 0.84
Date Sun, 24 Jun 2012 16:16:25 -0700
From Charles Hixson <charleshixsn@earthlink.net>
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.16) Gecko/20120506 Icedove/3.0.11
MIME-Version 1.0
To python-list@python.org
Subject Re: exception problem
References <4FE79433.8020704@earthlink.net> <4FE7982C.5020708@mrabarnett.plus.com>
In-Reply-To <4FE7982C.5020708@mrabarnett.plus.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
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.1466.1340579780.4697.python-list@python.org> (permalink)
Lines 46
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1340579780 news.xs4all.nl 6861 [2001:888:2000:d::a6]:49779
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:24406

Show key headers only | View raw


On 06/24/2012 03:43 PM, MRAB wrote:
> On 24/06/2012 23:26, Charles Hixson wrote:
>> The code:
>>                   print    ("pre-chunkLine")
>>                   chunks    =    []
>>                   try:
>>                       chunks    =    self.chunkLine (l)
>>                   except:
>>                       print    ("caught exception")
>>                       print (sys.exc_info()[:2])
>>                   finally:
>>                       print ("at finally")
>>                   print ("chunks =")
>>                   print (repr(chunks), ".", end = ":")
>> produces this result:
>>     . . ., by
>> pre-chunkLine
>> caught exception
>> at finally
>> path  3...
>>
>> Any suggestions as to what's wrong with the code?
>> FWIW, chunkLine begins:
>>       def chunkLine (self, line):
>>           print    ("chunkLine: ")
>>           print ("line = ", line)
>>           if    line == None:
>>               return    []
>>           assert    (isinstance (line, str) )
>>
> Don't use a bare "except"; it'll catch _any__exception. Catch only what
> you expect.
>
> For all I know, it could be that the name "l" doesn't exist.
But what I wanted was to catch any exception.  A problem was happening 
and I had no clue as to what it was.  (It turned out to be "self is not 
defined".  A silly mistake, but a real one.)

The odd thing was that if I ran it without the try block, I didn't get 
any exceptions at all.  (Which I clearly should have, except that since 
self wasn't defined, I'd usually expect the interpreter to detect the 
error before trying to execute the code.)

-- 
Charles Hixson

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


Thread

Re: exception problem Charles Hixson <charleshixsn@earthlink.net> - 2012-06-24 16:16 -0700
  Re: exception problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-06-25 07:48 +0000
    Re: exception problem Charles Hixson <charleshixsn@earthlink.net> - 2012-06-27 17:13 -0700
      Re: exception problem alex23 <wuwei23@gmail.com> - 2012-06-27 17:36 -0700
      Re: exception problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-06-28 03:44 +0000
    Re: exception problem Ethan Furman <ethan@stoneleaf.us> - 2012-06-28 05:52 -0700

csiph-web