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


Groups > comp.lang.python > #40348

Re: Dealing with exceptions

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <kwpolska@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'exception': 0.03; 'that?': 0.05; 'things.': 0.05; 'filenames': 0.07; 'see:': 0.07; 'suppose': 0.07; 'tests,': 0.07; 'try:': 0.07; 'command.': 0.09; 'ioerror': 0.09; 'loop.': 0.09; 'oserror': 0.09; 'cc:addr:python-list': 0.10; 'sat,': 0.15; 'dump': 0.16; 'gpg': 0.16; 'scratch': 0.16; 'wrote:': 0.17; 'char': 0.17; 'unicode': 0.17; 'exceptions': 0.22; 'parse': 0.22; 'cc:2**0': 0.23; 'errors': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'creating': 0.26; 'guess': 0.27; 'handling': 0.27; 'disk': 0.27; 'message-id:@mail.gmail.com': 0.27; 'actual': 0.28; 'run': 0.28; 'url:mailman': 0.29; 'case,': 0.29; 'this.': 0.29; "i'm": 0.29; 'maybe': 0.29; 'figure': 0.30; 'code': 0.31; '(and': 0.32; 'url:python': 0.32; 'url:listinfo': 0.32; 'certain': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'list': 0.35; 'bigger': 0.35; 'doing': 0.35; 'pm,': 0.35; 'something': 0.35; 'there': 0.35; 'really': 0.36; 'except': 0.36; 'but': 0.36; 'url:org': 0.36; 'subject:with': 0.36; 'should': 0.36; 'possible': 0.37; 'well.': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'skip:o 20': 0.38; 'some': 0.38; 'little': 0.39; 'url:mail': 0.40; 'think': 0.40; 'most': 0.61; 'time,': 0.62; 'times': 0.63; '2013': 0.84; 'commands.': 0.84; 'manual,': 0.84; 'url:tk': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=wWmXJm5nTCeE6QuOTh5dPeaCDBaRXz8aOTCD4T/daqE=; b=udlSoroFqAW6kFUjGI8ZaUM678OajxmxtVAvjigToJFzjMEiIZ8szibXsybdzoulUQ WbM43m8B1Mmn7Jqn1mrN7vrDZKoaP3Ep6IVIhLjEnaBHgI7DiY+0WARf1NnJ5z13CQAz kWGX9EnGejzC1wxx37rpxGw8mk+dj7aDT1L7geEVBQneZGH+I1x4f1zx36adpH2l83rU OMiFBmPo+veyIZ/QDIu/wl+aVHJF729d3s34Ae6WS4BzGSyR3ZRQg1n4nSgocDO0fH3A 2qMjI4wfM25K+JCLcIPBecA+aooKufwvSUNyLs9Jy3bYUwq8OdikzBotJ28IyqMFeRgz M7zQ==
X-Received by 10.42.30.132 with SMTP id v4mr15481928icc.34.1362246759898; Sat, 02 Mar 2013 09:52:39 -0800 (PST)
MIME-Version 1.0
In-Reply-To <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com>
References <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com>
From Kwpolska <kwpolska@gmail.com>
Date Sat, 2 Mar 2013 18:52:19 +0100
Subject Re: Dealing with exceptions
To bvdp <bob@mellowood.ca>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org
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.2785.1362246769.2939.python-list@python.org> (permalink)
Lines 43
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1362246769 news.xs4all.nl 6879 [2001:888:2000:d::a6]:45056
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:40348

Show key headers only | View raw


On Sat, Mar 2, 2013 at 6:40 PM, bvdp <bob@mellowood.ca> wrote:
> Every time I write a program with exception handling (and I suppose that includes just about every program I write!) I need to scratch my brain when I create try blocks.
>
> 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. Let's see:
>
>   IOError  that means that the disk is full or otherwise buggered. Better dump out of the loop.
>
> But, I know there can be other errors as well. Doing some tests, I know that certain filenames are invalid (I think a "?" or unicode char is invalid when writing to a FAT32 filesystem). And, so what exception is that? Without actually creating the error, I can't figure it out.
>
> In this case, I can run the program an number of times and parse out the errors and write code to catch various things. But, I think I'm missing something completely. Guess what I'm looking for is a list of possible (probable?) errors for the shutil.copy() command. And, in a much bigger manual, for most other commands.
>
> Maybe I'm just venting about FAT32 filesystems :)
>
> --
> http://mail.python.org/mailman/listinfo/python-list

IOError and OSError should cover all copy problems, I think.

Also, you can do `except:` for a catch-all, but it is discouraged
unless you have REALLY good reasons to do this.  And, most of the
time, you don’t.

-- 
Kwpolska <http://kwpolska.tk> | GPG KEY: 5EAAEA16
stop html mail                | always bottom-post
http://asciiribbon.org        | http://caliburn.nl/topposting.html

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