Python try/except not working
The point in the code which raises the error must be inside the try
block. In this case, it's likely that the error is raised inside the docopy
function, but that isn't enclosed in a try
block.
Note that docopy
returns None
. As such, you will raise an exception when you try to make an iter
out of None
-- but it won't be a ftplib.error_perm
exception, it'll be a TypeError
The except
clause will only catch exceptions that are raise
d inside of their corresponding try
block. Try putting the docopy
function call inside of the try
block as well:
def hmm(haha):
try:
result = docopy(haha)
it = iter(result)
except ftplib.error_perm:
print "Error Getting File"