Dealing with exceptions

Terry Reedy tjreedy at udel.edu
Sat Mar 2 22:23:37 CET 2013


On 3/2/2013 12:40 PM, bvdp wrote:

> But, I know there can be other errors as well. Doing some tests, I
> know that certain filenames are invalid (I think a "?" or unicode
> char is invalid when writing to a FAT32 filesystem). And, so what
> exception is that? Without actually creating the error, I can't
> figure it out.

So use the interactive interpreter (or idle, or ipython) and create the 
error. You should always have it open when editing. Using less time that 
it took you to write the above. 3.3, win7, (idle)

 >>> open('sdjhfjshdfkjsh')
Traceback (most recent call last):
   File "<pyshell#2>", line 1, in <module>
     open('sdjhfjshdfkjsh')
FileNotFoundError: [Errno 2] No such file or directory: 'sdjhfjshdfkjsh'

Now, does shutil pass on FileNotFoundError? I will let you experiment.

There are error conditions that are hard to generate, but a bad file 
name is not one of them.

-- 
Terry Jan Reedy




More information about the Python-list mailing list