common mistakes in this simple program

Chris Angelico rosuav at
Mon Feb 29 13:34:41 EST 2016

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


More information about the Python-list mailing list