RE: exception problem

Discussion in 'Python' started by Shambhu Rajak, Jun 25, 2012.

  1. If you are not sure about the Exception, You can adopt a generic way of handling exception.

    try:
    .....
    except Exception,e:
    print str(e)

    -Shambhu


    -----Original Message-----
    From: MRAB [mailto:p]
    Sent: 25/06/2012 4:14 AM
    To:
    Subject: Re: exception problem

    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.
     
    Shambhu Rajak, Jun 25, 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,536
  2. jeff
    Replies:
    3
    Views:
    1,692
    Scott
    Jun 26, 2003
  3. Kerri
    Replies:
    2
    Views:
    13,044
    Kevin Spencer
    Oct 27, 2003
  4. Ola
    Replies:
    0
    Views:
    538
  5. Selen
    Replies:
    0
    Views:
    2,688
    Selen
    May 28, 2004
Loading...

Share This Page