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


Groups > comp.lang.python > #40349

Re: Dealing with exceptions

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@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; 'python': 0.09; 'command.': 0.09; 'ioerror': 0.09; 'loop.': 0.09; 'oserror': 0.09; 'subclass': 0.09; 'sat,': 0.15; 'dump': 0.16; 'oserror.': 0.16; 'scratch': 0.16; 'wrote:': 0.17; 'char': 0.17; 'unicode': 0.17; 'exceptions': 0.22; 'parse': 0.22; 'errors': 0.23; 'specifically': 0.24; 'header :In-Reply-To:1': 0.25; 'creating': 0.26; 'am,': 0.27; 'guess': 0.27; 'handling': 0.27; 'disk': 0.27; 'message- id:@mail.gmail.com': 0.27; 'actual': 0.28; 'run': 0.28; 'case,': 0.29; "i'm": 0.29; 'figure': 0.30; 'expect': 0.31; 'code': 0.31; '(and': 0.32; 'certain': 0.33; 'to:addr:python-list': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'list': 0.35; 'bigger': 0.35; 'doing': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'except': 0.36; 'subject:with': 0.36; 'possible': 0.37; 'received:209': 0.37; 'well.': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'skip:o 20': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'little': 0.39; 'think': 0.40; 'most': 0.61; 'wide': 0.62; 'times': 0.63; 'more': 0.63; '2013': 0.84; 'commands.': 0.84; 'manual,': 0.84; 'to:name:python': 0.84
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:content-type:content-transfer-encoding; bh=IfEnT/SOa1pj7Z/aTbSHnKF5mLN6q1+HmVLeWlxpYF8=; b=SDS/Ygis4KmWNQxPZRDoiVGYJMxhrU7VwqL09ois5t30E86AEUNpuMUhoR+Zory1vB ZzXh/Xp8ahONxwOG1UcB+bi//1nxofGl4/jdBsPUIOJkddAjpS8YTfoF9d0uH2g8kSgV oueCkmFCFApQi5ajoXo3hTgoGYK/ScfLHeG9Dx1MrUVHphAM3r9IP9zjTav17fjqhMSm XJCOliW5jBMv7Pr9UiHUdxiv7mindTAi+UXnOa+7Wnev1SuRJ08NzinDQw97DsaigejW PmmV7UC2asM8blIx1R39eRcx/W3XuiSaDuVfTjBbCNcklkmarbQS+EjCyoTLS2L4s+Jb LLdQ==
X-Received by 10.220.239.71 with SMTP id kv7mr5591061vcb.46.1362247132695; Sat, 02 Mar 2013 09:58:52 -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 Ian Kelly <ian.g.kelly@gmail.com>
Date Sat, 2 Mar 2013 10:58:12 -0700
Subject Re: Dealing with exceptions
To Python <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
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.2786.1362247140.2939.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1362247140 news.xs4all.nl 6955 [2001:888:2000:d::a6]:51593
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:40349

Show key headers only | View raw


On Sat, Mar 2, 2013 at 10:40 AM, 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.

OSError.  In Python 3, I expect it would more specifically be a
FileNotFoundError, which is a subclass of OSError.

> 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.

OSError will cover a wide swath of possible exceptions here.

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