Re: exception problem

Discussion in 'Python' started by MRAB, Jun 24, 2012.

  1. MRAB

    MRAB Guest

    On 24/06/2012 23:26, 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) )
    >

    Don't use a bare "except"; it'll catch _any__exception. Catch only what
    you expect.

    For all I know, it could be that the name "l" doesn't exist.
     
    MRAB, Jun 24, 2012
    #1
    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:
    542
  5. Selen
    Replies:
    0
    Views:
    2,695
    Selen
    May 28, 2004
Loading...

Share This Page