Re: exception problem

Discussion in 'Python' started by Dave Angel, Jun 24, 2012.

  1. Dave Angel

    Dave Angel Guest

    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
     
    Dave Angel, Jun 24, 2012
    #1
    1. Advertising

  2. 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
     
    Steven D'Aprano, Jun 25, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jeff
    Replies:
    0
    Views:
    1,541
  2. jeff
    Replies:
    3
    Views:
    1,703
    Scott
    Jun 26, 2003
  3. Kerri
    Replies:
    2
    Views:
    13,057
    Kevin Spencer
    Oct 27, 2003
  4. Ola
    Replies:
    0
    Views:
    541
  5. Selen
    Replies:
    0
    Views:
    2,695
    Selen
    May 28, 2004
Loading...

Share This Page