Path: csiph.com!feeder.erje.net!2.eu.feeder.erje.net!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: common mistakes in this simple program Date: Tue, 1 Mar 2016 05:34:41 +1100 Lines: 24 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de FxaixgSJYNyvmrCw+sFfKQNP5PvMTS9KsFKUYu10jzFA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'error:': 0.05; 'cc:addr :python-list': 0.09; 'exception': 0.13; 'output': 0.13; 'ignore': 0.14; '2016': 0.16; 'behaviour.': 0.16; 'cc:name:python': 0.16; 'clause,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'i.e': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:program': 0.16; 'subject:simple': 0.16; 'trap': 0.16; 'wrote:': 0.16; 'later': 0.16; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'assuming': 0.22; 'exceptions': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'example': 0.26; 'command': 0.26; 'error': 0.27; 'handling': 0.27; 'message-id:@mail.gmail.com': 0.27; 'see,': 0.27; 'this.': 0.28; 'fine': 0.28; 'for,': 0.29; 'run': 0.33; 'tue,': 0.34; 'received:google.com': 0.35; 'but': 0.36; 'instead': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'say': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'ever': 0.60; 'mar': 0.65; 'else.': 0.66; 'chrisa': 0.84; 'subject:common': 0.84; 'subject:this': 0.85; 'to:none': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=FTCN9HQxHcB9EF7uSvmia9DsN8LAQ4/fTKq9ndmANrI=; b=jhsV619CgjKZRkVIuwIIaa4gvbwWv1XiVv66+y9xNarswYVqDXl7XbtL9VGJoIXb2l i2J5Vig97NuMTEhMp6KPbnkrsIi9+i+wWMezXPu7Gneq3D+PmqP9b1iCioF9UEtKhCdK gJdUhGhS/RnwceB8SLkPVRFsiyh7v4eSe+iJWdf+7I8H5mDzWhW+j6dBr7mwAVMpAA1x C+nFa71xhPlw238UDI7ZL+Jpk2i5IuS0m2UJJ6/bPvQYAcou8YIUlW+Ke/gyS/RioawV 86rXWNKToY93kOr5X2GOiUAmn+taMNHlDOjFHTgBMsrIU2DUNn7tPL7Iw0epE405Q+wB rMrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=FTCN9HQxHcB9EF7uSvmia9DsN8LAQ4/fTKq9ndmANrI=; b=QHo0zTEyg+Njd/59teGF4KgNYZ6KuoXIQ+1a9y/DwYt+8tC9bylGcq6tcLqxxv0ejY YzwjEvxY6w+DLiUPu+0Lk4UnBtksRhKkvOZiIMBNLKyjxxGzkOnut3PLeHfOVoK0gQOQ fdoBHMTX/MEkdyCt8at2mNpWqVowmfGpTF88velB0mPyrFL+jj8YN7fgCcXPE8MXPOIF I5zcKWVB3Gq/b04bRyY3dglUYAMZLiQefFoCwLsy4KKrPDWfwJGHBXmX2eRG+yosB1xf kx3TuhaRJENEfAk5uPctcDJJk+JIdz9rtXQUXJx6eUwFbjR6RteYnZEFNYfE1suCElNJ G1tw== X-Gm-Message-State: AD7BkJKi6RgJpGi2ls6kMRw+iZYXJG6HkUgXhBN5SxFsdVQfa5Q2aw0dH7fbmSQW+jYtwHK6pwfnVykbGWx+Ew== X-Received: by 10.50.43.168 with SMTP id x8mr11491058igl.92.1456770881899; Mon, 29 Feb 2016 10:34:41 -0800 (PST) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:103752 On Tue, Mar 1, 2016 at 5:21 AM, Ganesh Pal wrote: > > In my case the exception is nothing but the error example if we plan > to run the command say #ifconfig -a and the command fails because of > a type ( say u ran #igconfig -a). > > we will the output as > > # Failed to run igconfig -a got Error (ret=127) > out : > error: command not found: igconfig > > So the execption is the error i.e Error (ret=127) out : error: command > not found: igconfig, Iam fine with this behaviour. > You're falling into the trap of assuming that the only exception you can ever get is the one that you're planning for, and then handling ALL exceptions as though they were that one. Instead catch ONLY the exception that you're expecting to see, and ignore everything else. Do not use a bare "except:" clause, nor even "except Exception:", for this. You will appreciate it later on. ChrisA