473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Why can not catch the inner exception

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
2 1538

"ÈËÑÔÂäÈÕÊÇÌìÑÄ£¬Íû¼«ÌìÑIJ»¼û¼Ò" <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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: kaeli | last post by:
Hey all, I'd like to start using the try/catch construct in some scripts. Older browsers don't support this. What's the best way to test for support for this construct so it doesn't kill...
3
by: Steve | last post by:
I have some general catch clauses in my app as follows: try { } catch(Exception ex) { } try
11
by: Pohihihi | last post by:
I was wondering what is the ill effect of using try catch in the code, both nested and simple big one. e.g. try { \\ whole app code goes here } catch (Exception ee) {}
5
by: Steve Murphy | last post by:
I have a couple of standard Try/Catch blocks that I use repeatedly. Is there anyway to wrap these blocks into a method call? Or does C# have anything like a C++ macro? Thanks, Steve Murphy
13
by: Bit byte | last post by:
Is there any way of retrievieng error information (say, from a 'global' or system wide) error object - when you are in a catch all statement block? Sometimes it cannot be helped, when something...
3
by: Michael C | last post by:
I'm writing an app on the PDA using C# with .net 1.1. It is all working well except in some cases a try catch is simply ignored and a totally different error is returned. I've got code like below...
0
by: dlabar | last post by:
I am trying to update data that is linked in two different databases. If the attempt to save the data in database 1 fails, I need to do some cleanup in database 2 and E-mail that the error occured. ...
9
by: SMH | last post by:
Hi, I am making the transition from VB to C# I am struggling to get my try/catch to work. For some reason, the exception is not caught. My code is below, any help will be much appreciated. ...
4
by: Elmo Watson | last post by:
I've got one main method, with a Try Catch block. In that, I catch the error and put it on a label. However, inside the Try portion, I also run another method. I have a Try/Catch block there,...
4
by: =?Utf-8?B?UmljaA==?= | last post by:
I have to read data from an Excel Sheet. Using Microsoft Office Interop and Automation I create an Excel object Dim xl As New Excel.Application, wkbk As Excel.Workbook, rng as Excel.Range I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.