Dealing with exceptions

Chris Angelico rosuav at gmail.com
Sat Mar 2 18:17:55 EST 2013


On Sun, Mar 3, 2013 at 10:08 AM, Terry Reedy <tjreedy at udel.edu> wrote:
> On 3/2/2013 5:16 PM, Chris Angelico wrote:
>>
>> On Sun, Mar 3, 2013 at 8:23 AM, Terry Reedy <tjreedy at udel.edu> wrote:
>>>>>>
>>>>>> 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.
>>
>>
>> That's actually a perfectly valid file name, but one that doesn't
>> happen to have a corresponding file. However, the same technique will
>> work with the OP's description of "a filename which the FAT32 didn't
>> like" too.
>
>
> Yeah, that gives a different error and message.
>>>> open('a~`!@#$%^&*()_-+={[}]|\<,>.?/')
>
> Traceback (most recent call last):
>   File "<pyshell#3>", line 1, in <module>
>     open('a~`!@#$%^&*()_-+={[}]|\<,>.?/')
> OSError: [Errno 22] Invalid argument: 'a~`!@#$%^&*()_-+={[}]|\\<,>.?/'

That should be:

OSError: Profanity not permitted on respectable file systems

ChrisA



More information about the Python-list mailing list