Why can not catch the inner exception

  • Thread starter =?gb2312?B?yMvR1MLkyNXKx8zs0cSjrM37vKvM7NHEsru8+7z
  • Start date
?

=?gb2312?B?yMvR1MLkyNXKx8zs0cSjrM37vKvM7NHEsru8+7z

Please see the follow code, I can not catch the exception " IOError"
raised from shutil.copyfile() , why?
try:
if (DEST_TYPE & TYPE_FTP):
fn = oname
ftpc.UploadFile(f, fn)
else:
fn = os.path.join(dst, oname)
shutil.copyfile(f, fn)

.... other code....

except [IOError, FtpcException],why:
num = 0
print >>sys.stderr, "can not copy '%s' to '%s':
%s"%(f, fn, why)
ERR_NUM += 1

I must do like this:
try:
if (DEST_TYPE & TYPE_FTP):
fn = oname
ftpc.UploadFile(f, fn)
else:
fn = os.path.join(dst, oname)
try:
shutil.copyfile(f, fn)
except IOError:
....

.... other code....

except [IOError, FtpcException],why:
num = 0
print >>sys.stderr, "can not copy '%s' to '%s':
%s"%(f, fn, why)
ERR_NUM += 1

Thanks!
 
M

Mark T

ÈËÑÔÂäÈÕÊÇÌìÑÄ£¬Íû¼«ÌìÑIJ»¼û¼Ò said:
Please see the follow code, I can not catch the exception " IOError"
raised from shutil.copyfile() , why?
try:
if (DEST_TYPE & TYPE_FTP):
fn = oname
ftpc.UploadFile(f, fn)
else:
fn = os.path.join(dst, oname)
shutil.copyfile(f, fn)

.... other code....

except [IOError, FtpcException],why:
num = 0
print >>sys.stderr, "can not copy '%s' to '%s':
%s"%(f, fn, why)
ERR_NUM += 1

I must do like this:
try:
if (DEST_TYPE & TYPE_FTP):
fn = oname
ftpc.UploadFile(f, fn)
else:
fn = os.path.join(dst, oname)
try:
shutil.copyfile(f, fn)
except IOError:
....

.... other code....

except [IOError, FtpcException],why:
num = 0
print >>sys.stderr, "can not copy '%s' to '%s':
%s"%(f, fn, why)
ERR_NUM += 1

Thanks!

ÄãºÃ,

Use a tuple (IOError,FtpcException) instead of a list in the except
statement and it works.

--Âí¿Ë
 
G

Guest

Please see the follow code, I can not catch the exception " IOError"
raised from shutil.copyfile() , why?
try:
if (DEST_TYPE & TYPE_FTP):
fn = oname
ftpc.UploadFile(f, fn)
else:
fn = os.path.join(dst, oname)
shutil.copyfile(f, fn)
.... other code....
except [IOError, FtpcException],why:
num = 0
print >>sys.stderr, "can not copy '%s' to '%s':
%s"%(f, fn, why)
ERR_NUM += 1
I must do like this:
try:
if (DEST_TYPE & TYPE_FTP):
fn = oname
ftpc.UploadFile(f, fn)
else:
fn = os.path.join(dst, oname)
try:
shutil.copyfile(f, fn)
except IOError:
....
.... other code....
except [IOError, FtpcException],why:
num = 0
print >>sys.stderr, "can not copy '%s' to '%s':
%s"%(f, fn, why)
ERR_NUM += 1

,

Use a tuple (IOError,FtpcException) instead of a list in the except
statement and it works.

-- - -

- -

Thank you!
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top