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


Groups > comp.lang.python > #98553

Re: How to handle exceptions properly in a pythonic way?

X-Received by 10.129.83.85 with SMTP id h82mr123650ywb.0.1447105423652; Mon, 09 Nov 2015 13:43:43 -0800 (PST)
X-Received by 10.50.18.40 with SMTP id t8mr2947igd.2.1447105423493; Mon, 09 Nov 2015 13:43:43 -0800 (PST)
Path csiph.com!au2pb.net!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!b51no76056qgf.0!news-out.google.com!l1ni1443igd.0!nntp.google.com!i2no1965425igv.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.python
Date Mon, 9 Nov 2015 13:43:42 -0800 (PST)
In-Reply-To <mailman.44.1446699105.16136.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=109.60.108.225; posting-account=19izYAoAAAA9JBIU5jzsuVhoPybSlW8-
NNTP-Posting-Host 109.60.108.225
References <4b303213-62e2-42d4-b2f6-4fc1f6025944@googlegroups.com> <n18fmg$oj6$1@reader1.panix.com> <e134f1a3-89cc-4497-807e-3dd0836fb5e6@googlegroups.com> <mailman.43.1446695916.16136.python-list@python.org> <4cb51da8-9331-4efe-87d3-dfe9c2ae0f8e@googlegroups.com> <mailman.44.1446699105.16136.python-list@python.org>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <70b30688-2558-4974-bdb8-e579f4ffa6fa@googlegroups.com> (permalink)
Subject Re: How to handle exceptions properly in a pythonic way?
From zljubisic@gmail.com
Injection-Date Mon, 09 Nov 2015 21:43:43 +0000
Content-Type text/plain; charset=ISO-8859-1
X-Received-Bytes 2237
X-Received-Body-CRC 2143074989
Xref csiph.com comp.lang.python:98553

Show key headers only | View raw


Hi,

> def get_html(...):
>     try:
>         ... actually go get the info
>         return info
>     except (ConnectionError, OSError, SocketError) as e:
>         raise ContentNotFoundError from e

Personally, I never liked "early returns". I would rather used a variable and the last line in the function would be return variable.
Anyway, I got the point.

> To use this code, what you'd do is:
> 
> try:
>     data = get_html(...)
> except ContentNotFoundError:
>     # deal with the case of not having anything to work with

I got a picture. Thanks.

I have to rethink now about two approaches. One would be as you have suggested in this mail - raising ContentNotFoundError, and another one would be not to mask root exceptions and deal with them instead of ContentNotFoundError.

You have clarified to me the concept. Thanks.

Regards. 

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


Thread

How to handle exceptions properly in a pythonic way? zljubisic@gmail.com - 2015-11-02 11:24 -0800
  Re: How to handle exceptions properly in a pythonic way? John Gordon <gordon@panix.com> - 2015-11-02 20:05 +0000
    Re: How to handle exceptions properly in a pythonic way? zljubisic@gmail.com - 2015-11-04 19:41 -0800
      Re: How to handle exceptions properly in a pythonic way? Chris Angelico <rosuav@gmail.com> - 2015-11-05 14:58 +1100
        Re: How to handle exceptions properly in a pythonic way? zljubisic@gmail.com - 2015-11-04 20:18 -0800
          Re: How to handle exceptions properly in a pythonic way? Chris Angelico <rosuav@gmail.com> - 2015-11-05 15:51 +1100
            Re: How to handle exceptions properly in a pythonic way? zljubisic@gmail.com - 2015-11-09 13:43 -0800
          Re: How to handle exceptions properly in a pythonic way? tian.su.yale@gmail.com - 2015-11-04 21:02 -0800
  Re: How to handle exceptions properly in a pythonic way? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-02 13:58 -0700
    Re: How to handle exceptions properly in a pythonic way? zljubisic@gmail.com - 2015-11-04 20:11 -0800
  Re: How to handle exceptions properly in a pythonic way? tian.su.yale@gmail.com - 2015-11-04 21:15 -0800
    Re: How to handle exceptions properly in a pythonic way? zljubisic@gmail.com - 2015-11-09 13:36 -0800

csiph-web