Re: question about try/except blocks
On Thu, May 2, 2013 at 9:54 PM, J <email@example.com> wrote:
> Would it be better to wrap the call and catch the OSError there, or
> wrap the whole with open() block in the function itself?
> My thought is to wrap the with open() call in the function so that I'm
> not wrapping the function call every time I use the class somewhere,
> but then I am not sure of that as it leads to nested try blocks like
It definitely shouldn't be done that way, since you might catch
exceptions in other circumstances too. Try this:
f = open(dest, 'wb', 0)
except OSError as exc:
except IOError as exc:
> with open(dest, 'wb', 0) as outfile:
> except IOError as exec:
> more stuff
> other stuff
> except OSError as exc:
> error handling stuff
> return False
> I think, functionally, that should work, but should nested try/except
> blocks be avoided?
|All times are GMT. The time now is 03:16 AM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.