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: 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 Date: Sat, 2 Mar 2013 10:58:12 -0700 Subject: Re: Dealing with exceptions To: Python 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Sat, Mar 2, 2013 at 10:40 AM, bvdp 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 t= hat certain filenames are invalid (I think a "?" or unicode char is invalid= when writing to a FAT32 filesystem). And, so what exception is that? Witho= ut 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 som= ething completely. Guess what I'm looking for is a list of possible (probab= le?) errors for the shutil.copy() command. And, in a much bigger manual, fo= r most other commands. OSError will cover a wide swath of possible exceptions here.