[Tutor] Successfully trapping the [505 file not found] error

Luke Paireepinart rabidpoobear at gmail.com
Thu May 27 01:16:36 CEST 2010


>
> What follows is the exception handling snippet:
> ## ------------------------------------------------------------------
> except ftplib.error_perm, e:
>    msg = "Couldn't get %s ---- %s" % (fname,str(sys.exc_info()[1]))
>        log.add(msg)
>        more-code-follows
> ## ------------------------------------------------------------------
> When the code above is successful, the application simply
> logs the exception and continues.
> When the code above fails the traceback is as follows:
>

Are you sure you aren't doing anything with the ftp object in the
"more code follows"?
You are probably creating another error of the same type while
processing your exception, so the second one doesn't get caught.

like this (except with ftp obviously):
try:
    f = open('in.txt')
except IOError:
    y = open('log.txt', 'w')
    y.write('failed!')
    y.close()


More information about the Tutor mailing list