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


Groups > comp.lang.python > #53028 > unrolled thread

Re: Missing something on exception handling in Python 3

Started byEthan Furman <ethan@stoneleaf.us>
First post2013-08-26 20:16 -0700
Last post2013-08-26 20:16 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#53028 — Re: Missing something on exception handling in Python 3

FromEthan Furman <ethan@stoneleaf.us>
Date2013-08-26 20:16 -0700
SubjectRe: Missing something on exception handling in Python 3
Message-ID<mailman.254.1377574592.19984.python-list@python.org>
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~

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web