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


Groups > comp.lang.python > #24404 > unrolled thread

Re: exception problem

Started byDave Angel <d@davea.name>
First post2012-06-24 18:45 -0400
Last post2012-06-25 07:40 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: exception problem Dave Angel <d@davea.name> - 2012-06-24 18:45 -0400
    Re: exception problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-06-25 07:40 +0000

#24404 — Re: exception problem

FromDave Angel <d@davea.name>
Date2012-06-24 18:45 -0400
SubjectRe: exception problem
Message-ID<mailman.1464.1340577976.4697.python-list@python.org>
On 06/24/2012 06:30 PM, Charles Hixson wrote:
> Sorry, I left out:
> er$ python3 --version
> Python 3.2.3rc1
>
> On 06/24/2012 03:26 PM, 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) )
>>
>
>

On your except line, you forgot both the type of exception you're
expecting and the variable to receive its value.  So you're masking all
errors, including a name error finding chunkline().

You don't include enough code to make the fragment executable, so I'd
have to just guess.  I'm guessing that chunkline() is not defined in the
same class as that first method, whatever it was called.

If this were my problem, probably first thing I'd try is to remove the
try and catch, and see what it shows.  Bare exceptions are the bane of
programming;  Using it is like trying to learn to drive while blindfolded.



-- 

DaveA

[toc] | [next] | [standalone]


#24418

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2012-06-25 07:40 +0000
Message-ID<4fe815e0$0$29866$c3e8da3$5496439d@news.astraweb.com>
In reply to#24404
On Sun, 24 Jun 2012 18:45:45 -0400, Dave Angel wrote:

> Bare exceptions are the bane of
> programming;  Using it is like trying to learn to drive while
> blindfolded.

+1 QOTW

I really wish bare exceptions were removed from Python 3. There's no 
point to try...except any longer, and it's just an attractive nuisance to 
beginners.


-- 
Steven

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web