Re: How to Catch 2 Exceptions at once?

Discussion in 'Python' started by Steve Holden, Oct 1, 2006.

  1. Steve Holden

    Steve Holden Guest

    Gregory Piñero wrote:
    > How can I catch 2 exceptions at once for example:
    >
    > try:
    > 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:

    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.

    regards
    Steve
    --
    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
     
    Steve Holden, Oct 1, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Black
    Replies:
    8
    Views:
    4,213
    Xenos
    Aug 20, 2004
  2. =?ISO-8859-1?Q?Gregory_Pi=F1ero?=

    How to Catch 2 Exceptions at once?

    =?ISO-8859-1?Q?Gregory_Pi=F1ero?=, Oct 1, 2006, in forum: Python
    Replies:
    2
    Views:
    403
    John Machin
    Oct 1, 2006
  3. Replies:
    6
    Views:
    499
    Stan Kitsis [MSFT]
    Mar 8, 2007
  4. Adam
    Replies:
    9
    Views:
    612
    red floyd
    Feb 2, 2006
  5. Gancy
    Replies:
    4
    Views:
    241
    Rasto Levrinc
    Feb 3, 2005
Loading...

Share This Page