exception problem

Dave Angel d at davea.name
Sun Jun 24 18:45:45 EDT 2012


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




More information about the Python-list mailing list