skip Trackback error for ftp checking

Chris Angelico rosuav at gmail.com
Mon Nov 12 05:23:00 EST 2012


On Mon, Nov 12, 2012 at 8:25 PM, moonhkt <moonhkt at gmail.com> wrote:
> On Nov 10, 2:50 pm, Steven D'Aprano <steve
> +comp.lang.pyt... at pearwood.info> wrote:
>>
>> The same way you would skip any other error when you do something wrong:
>> catch the exception.
>
> Thank. Added below.
> try:
>    ftp = FTP(options.remote_host_address)
> except :
>       print "Host address not found."
>       sys.exit(1)

Heh, I'm afraid that's not quite what Steven meant; what you're doing
there is literally skipping _any other error_. A bare except is
usually not a good thing. Catch the specific exception you want to
catch - that way, if you typo a name or something, you don't get an
obscure message about the host address when it's really a coding bug.

ChrisA



More information about the Python-list mailing list