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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Sun, Mar 3, 2013 at 4:40 AM, bvdp 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