By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,630 Members | 1,313 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,630 IT Pros & Developers. It's quick & easy.

Why can not catch the inner exception

P: n/a
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!

Jun 7 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"人言落日是天涯,望极天涯不见家" <ke********@gmail.comwrote in message
news:11*********************@n15g2000prd.googlegro ups.com...
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.

--马克

Jun 7 '07 #2

P: n/a
On 6 7 , 10 53 , "Mark T" <nos...@nospam.comwrote:
" " <kelvin....@gmail.comwrote in message

news:11*********************@n15g2000prd.googlegro ups.com...


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.

-- - -

- -
Thank you!
:-)

Jun 7 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.