How to Catch 2 Exceptions at once?

Gregory Piñero gregpinero at gmail.com
Sat Sep 30 22:09:19 EDT 2006


On 9/30/06, Steve Holden <steve at holdenweb.com> wrote:
> As usual, by adding an additional name after the exception specification:
>
>          try:
>              self.gses = opener.open(req)
>          except (urllib2.HTTPError,urllib2.URLError), exdata:
>              do something with exdata ...
>
> Pedantically speaking, of course, you aren't catching two exceptions at
> once because they don't occur simultaneously: you are writing a
> statement that catches either of two exceptions.
>

Thanks Steve!

I'll think about the two exceptions at once thing.  Sounds like a challenge ;-)

-Greg



More information about the Python-list mailing list