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


Groups > comp.lang.python > #40354

Re: Dealing with exceptions

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.017
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'exception': 0.03; 'try:': 0.07; 'abort': 0.09; 'propagate': 0.09; 'anyway': 0.11; '(meaning': 0.16; 'exception?': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'oserror.': 0.16; 'wrote:': 0.17; 'copied': 0.17; 'bit': 0.21; 'exceptions': 0.22; 'header:In- Reply-To:1': 0.25; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'actual': 0.28; 'trouble': 0.28; "i'm": 0.29; 'maybe': 0.29; 'error': 0.30; 'figure': 0.30; 'to:addr:python-list': 0.33; 'recommended': 0.33; 'received:google.com': 0.34; 'doing': 0.35; 'continue': 0.35; 'received:209.85': 0.35; 'except': 0.36; 'subject:with': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'skip:o 20': 0.38; 'to:addr:python.org': 0.39; 'little': 0.39; 'save': 0.61; 'yourself': 0.77; '2013': 0.84; 'console,': 0.84; 'songs': 0.91; 'hand,': 0.97
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=rjdl3LujA/9j/nDaUzrejwd+GKhDgwTxuUa6MBiiM5A=; b=K086lQ5gJH/CNzaXRftiE7cas507vD4lyiqYFKkFTyH5D17R5lgDPma0Jt/13UQ2wI 8CGC4qRbbZroKUifRFLJug6gax8siiII9yYxGDdyxY15Tnt/we4lvZgoxk3kmGVcWqHF nNBILHCbEtOUMuU+2OAL8a6EPnV6V5ozuWk7/h6hEMd8Hq43D8sbW14CliTLoNf3Yejz zsOCe0lp47n0UCybnEZX3Q3iJw+40lEo0Tlm/ui0qAPxAkCseOzY8OVTyRvHkdE2nVmu lnwbWxOalUfmzGg5KFpfJQcXQyyUD47dLWxbzDI0BCPAEf2zRp22zuE+jYKegA1JZBaP uqjg==
MIME-Version 1.0
X-Received by 10.58.56.161 with SMTP id b1mr5842606veq.42.1362248469973; Sat, 02 Mar 2013 10:21:09 -0800 (PST)
In-Reply-To <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com>
References <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com>
Date Sun, 3 Mar 2013 05:21:09 +1100
Subject Re: Dealing with exceptions
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2789.1362248472.2939.python-list@python.org> (permalink)
Lines 22
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1362248472 news.xs4all.nl 6909 [2001:888:2000:d::a6]:36330
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:40354

Show key headers only | View raw


On Sun, Mar 3, 2013 at 4:40 AM, bvdp <bob@mellowood.ca> wrote:
> For example, I'm writing a little program do copy specific files to a USB stick. To do the actual copy I'm using:
>
>     try:
>        shutil.copy(s, os.path.join(usbpath, songname))
>      except ...
>
> now, I need to figure out just what exceptions to handle.

Here's a bit of a left-field thought: Maybe none of them.

What are you actually doing when you get an exception? Can you
plausibly recover? If not - that is, if you're going to abort the
whole operation anyway - then save yourself the trouble of writing the
try/catch, and just let the exception propagate up (to the console, if
nowhere else).

On the other hand, if you want to simply report the error and continue
on (meaning you get as many songs copied as possible), then do what
others have recommended and catch OSError.

ChrisA

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


Thread

Dealing with exceptions bvdp <bob@mellowood.ca> - 2013-03-02 09:40 -0800
  Re: Dealing with exceptions Kwpolska <kwpolska@gmail.com> - 2013-03-02 18:52 +0100
    Re: Dealing with exceptions bvdp <bob@mellowood.ca> - 2013-03-02 11:35 -0800
      Re: Dealing with exceptions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-03 01:41 +0000
    Re: Dealing with exceptions bvdp <bob@mellowood.ca> - 2013-03-02 11:35 -0800
    Re: Dealing with exceptions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-03 00:41 +0000
      Re: Dealing with exceptions Chris Angelico <rosuav@gmail.com> - 2013-03-03 12:04 +1100
    Re: Dealing with exceptions Nobody <nobody@nowhere.com> - 2013-03-03 23:01 +0000
  Re: Dealing with exceptions Ian Kelly <ian.g.kelly@gmail.com> - 2013-03-02 10:58 -0700
  Re: Dealing with exceptions Ian Kelly <ian.g.kelly@gmail.com> - 2013-03-02 11:00 -0700
  Re: Dealing with exceptions Chris Angelico <rosuav@gmail.com> - 2013-03-03 05:21 +1100
    Re: Dealing with exceptions bvdp <bob@mellowood.ca> - 2013-03-02 11:39 -0800
    Re: Dealing with exceptions bvdp <bob@mellowood.ca> - 2013-03-02 11:39 -0800
  Re: Dealing with exceptions Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-03-02 19:18 +0000
  Re: Dealing with exceptions Devin Jeanpierre <jeanpierreda@gmail.com> - 2013-03-02 14:27 -0500
  Re: Dealing with exceptions Rick Johnson <rantingrickjohnson@gmail.com> - 2013-03-02 11:43 -0800
  Re: Dealing with exceptions Terry Reedy <tjreedy@udel.edu> - 2013-03-02 16:23 -0500
  Re: Dealing with exceptions Chris Angelico <rosuav@gmail.com> - 2013-03-03 09:16 +1100
  Re: Dealing with exceptions Terry Reedy <tjreedy@udel.edu> - 2013-03-02 18:08 -0500
  Re: Dealing with exceptions Chris Angelico <rosuav@gmail.com> - 2013-03-03 10:17 +1100

csiph-web