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


Groups > comp.lang.python > #103752

Re: common mistakes in this simple program

From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: common mistakes in this simple program
Date 2016-03-01 05:34 +1100
Message-ID <mailman.37.1456770890.20602.python-list@python.org> (permalink)
References <CACT3xuWUk02Or78XHTdkFLsy6CMVHEYKOyid3hFJxw8Wh6-g1A@mail.gmail.com> <CALwzid=3sN3ic=wrq8qn+0P+Zs8xGn1TJRLYL35B1Qk-vDeh5g@mail.gmail.com> <CACT3xuXn1zCip-io9aQ_i0Av_tR-7AHbwq3bX2HbvdmyC_i9qA@mail.gmail.com> <CALwzidn8-HDrGSqZT2ODxhdNYL7yFt5hdmC8RnB4WC=gkD4Wtg@mail.gmail.com> <CACT3xuVxn+XuEa3xLNb+9wQ74cNWUZ8J3nmbkjKAtgq58gkLEg@mail.gmail.com>

Show all headers | View raw


On Tue, Mar 1, 2016 at 5:21 AM, Ganesh Pal <ganesh1pal@gmail.com> 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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: common mistakes in this simple program Chris Angelico <rosuav@gmail.com> - 2016-03-01 05:34 +1100

csiph-web