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


Groups > comp.lang.python > #24404

Re: exception problem

Date 2012-06-24 18:45 -0400
From Dave Angel <d@davea.name>
Subject Re: exception problem
References <4FE79433.8020704@earthlink.net> <4FE794F1.6000202@earthlink.net>
Newsgroups comp.lang.python
Message-ID <mailman.1464.1340577976.4697.python-list@python.org> (permalink)

Show all headers | View raw


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

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


Thread

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

csiph-web