Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31242 > unrolled thread

Re: Understanding and dealing with an exception

Started byMark Lawrence <breamoreboy@yahoo.co.uk>
First post2012-10-14 09:20 +0100
Last post2012-10-14 09:20 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Understanding and dealing with an exception Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-10-14 09:20 +0100

#31242 — Re: Understanding and dealing with an exception

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2012-10-14 09:20 +0100
SubjectRe: Understanding and dealing with an exception
Message-ID<mailman.2171.1350202826.27098.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web