Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #24403

Re: exception problem

Date 2012-06-24 23:43 +0100
From MRAB <python@mrabarnett.plus.com>
Subject Re: exception problem
References <4FE79433.8020704@earthlink.net>
Newsgroups comp.lang.python
Message-ID <mailman.1463.1340577837.4697.python-list@python.org> (permalink)

Show all headers | View raw


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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: exception problem MRAB <python@mrabarnett.plus.com> - 2012-06-24 23:43 +0100

csiph-web