How to Catch 2 Exceptions at once?
steve at holdenweb.com
Sun Oct 1 03:43:20 CEST 2006
Gregory Piñero wrote:
> How can I catch 2 exceptions at once for example:
> self.gses = opener.open(req)
> except (urllib2.HTTPError,urllib2.URLError):
> do something..
> Seems to work, but how do I also get information about the error?
As usual, by adding an additional name after the exception specification:
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.
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the Python-list