Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.python

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 06-24-2012, 10:45 PM
Dave Angel
Guest
 
Posts: n/a
Default Re: exception problem

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

Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 06-25-2012, 07:40 AM
Steven D'Aprano
Guest
 
Posts: n/a
Default Re: exception problem

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
Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 10:15 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.