|
|
 |
 |
 |
 |
Python Programming Language
|
 |
 |
 |
 |
 |
 |
 |
 |
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!
" " <kelvin. @gmail.com> wrote in message news:1181215054.826742.75930@n15g2000prd.googlegroups.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. --
On 6 7 , 10 53 , "Mark T" <nos@nospam.com> wrote:
> " " <kelvin. @gmail.com> wrote in message > news:1181215054.826742.75930@n15g2000prd.googlegroups.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! :-)
|
 |
 |
 |
 |
|