Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Understanding and dealing with an exception

Reply
Thread Tools

Re: Understanding and dealing with an exception

 
 
Mark Lawrence
Guest
Posts: n/a
 
      10-14-2012
On 14/10/2012 05:23, Vincent Davis wrote:
> I am working on a script to find bad image files. I am using PIL
> and specifically image.verify() I have a set of known to be bad image files
> to test. I also what to be able to test any file for example a .txt and
> deal with the exception.
> Currently my code is basically
>
> try:
> im = Image.open(ifile)
> try:
> print(im.verify())
> except:
> print('Pil image.verify() failed: ' + afile)
> except IOError:
> print('PIL cannot identify image file: ' + afile)
> except:
> print(ifile)
> print("Unexpected error doing PIL.Image.open():", sys.exc_info()[0])
> raise


[snip]

>
> Vincent
>


You've already had some advice so I'll just point out that a bare except
is a bad idea as you wouldn't even be able to catch a user interrupt.
Try (groan!) catching StandardError instead.

--
Cheers.

Mark Lawrence.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Understanding and dealing with an exception Mark Lawrence Python 0 10-14-2012 11:17 AM
Re: Understanding and dealing with an exception Terry Reedy Python 0 10-14-2012 10:06 AM
Re: Understanding and dealing with an exception Chris Angelico Python 0 10-14-2012 05:09 AM
Re: Understanding and dealing with an exception Chris Angelico Python 0 10-14-2012 04:49 AM
Re: Understanding and dealing with an exception Chris Angelico Python 0 10-14-2012 04:31 AM



Advertisments