Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!eweka.nl!lightspeed.eweka.nl!194.134.4.91.MISMATCH!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; 'lawrence': 0.09; 'loop.': 0.09; 'oserror': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subclass': 0.09; 'sat,': 0.15; 'dump': 0.16; 'oserror.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'scratch': 0.16; 'url:whatsnew': 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; 'header:User-Agent:1': 0.26; 'creating': 0.26; 'am,': 0.27; 'guess': 0.27; 'handling': 0.27; 'disk': 0.27; 'header:X -Complaints-To:1': 0.28; '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; 'url:python': 0.32; 'from:addr:yahoo.co.uk': 0.32; 'certain': 0.33; 'to:addr:python-list': 0.33; "can't": 0.34; 'list': 0.35; 'bigger': 0.35; 'doing': 0.35; 'something': 0.35; 'there': 0.35; 'received:org': 0.36; 'except': 0.36; 'url:org': 0.36; "wasn't": 0.36; 'subject:with': 0.36; 'possible': 0.37; 'well.': 0.37; 'subject:: ': 0.38; 'mark': 0.38; 'files': 0.38; 'skip:o 20': 0.38; 'some': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'little': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'most': 0.61; 'wide': 0.62; 'times': 0.63; 'more': 0.63; '2013': 0.84; 'commands.': 0.84; 'manual,': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Dealing with exceptions Date: Sat, 02 Mar 2013 19:18:16 +0000 References: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-92-18-29-221.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:17.0) Gecko/20130215 Thunderbird/17.0.3 In-Reply-To: X-Antivirus: avast! (VPS 130302-0, 02/03/2013), Outbound message X-Antivirus-Status: Clean 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1362251858 news.xs4all.nl 6845 [2001:888:2000:d::a6]:45391 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:40355 On 02/03/2013 17:58, Ian Kelly wrote: > 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 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. This wasn't introduced until Python 3.3 see http://docs.python.org/3/whatsnew/3.3.html#pep-3151-reworking-the-os-and-io-exception-hierarchy > >> 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. > -- Cheers. Mark Lawrence