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


Groups > comp.lang.python > #53028

Re: Missing something on exception handling in Python 3

Date 2013-08-26 20:16 -0700
From Ethan Furman <ethan@stoneleaf.us>
Subject Re: Missing something on exception handling in Python 3
References <CANc-5Uztbwz5cYk6K8vdLdjaFSPOO4qmROvPoUqfGFCnW6JVqA@mail.gmail.com> <521C0B62.1030004@mrabarnett.plus.com> <CANc-5Uyi_EXHLHbe9v7U8iNL00iCO8T-JMnaiAUmcB5sz-qd_A@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.254.1377574592.19984.python-list@python.org> (permalink)

Show all headers | View raw


On 08/26/2013 07:49 PM, Skip Montanaro wrote:
>> Do this:
>>
>>      raise LockFailed("Failed to create %s" % self.path) from None
>
> Thanks. Is there some construct which will work in 2.x and 3.x?

Something like this (untested):

     exc = None
     try:
         write_pid_to_lockfile(somefile)
     except OSError as exc:
         exc = sys.exc_info()[0]   # not sure of index
     if exc:
         if conditions_i_can_handle:
             do_other_stuff...
         else:
             raise LockFailed("Failed to create %s" % self.path)

Since you're raising outside the try...except block you won't see the chained exception in Python3.

--
~Ethan~

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


Thread

Re: Missing something on exception handling in Python 3 Ethan Furman <ethan@stoneleaf.us> - 2013-08-26 20:16 -0700

csiph-web