Exception-handling

Discussion in 'Python' started by Odd-R., Feb 24, 2006.

  1. Odd-R.

    Odd-R. Guest

    I have come over a strange problem regarding exceptions
    This is my code:

    try:
    #some operation
    except Exception, info:
    #some message
    except:
    #??

    When executing my code, I get to the last block here. This
    I find rather strange, because I thought Exception would catch
    all exceptions. But this is obviously not the case here.

    What is this, and how can I get a hold of what causes the exception?

    Thanks!



    --
    Har du et kjøleskap, har du en TV
    så har du alt du trenger for å leve

    -Jokke & Valentinerne
     
    Odd-R., Feb 24, 2006
    #1
    1. Advertising

  2. Odd-R. wrote:

    > I have come over a strange problem regarding exceptions
    > This is my code:
    >
    > try:
    > #some operation
    > except Exception, info:
    > #some message
    > except:
    > #??
    >
    > When executing my code, I get to the last block here. This
    > I find rather strange, because I thought Exception would catch
    > all exceptions. But this is obviously not the case here.
    >
    > What is this, and how can I get a hold of what causes the exception?


    You can throw everything as an exception. I _think_ that is frowned upon
    these days, but it is there so it will happen.

    However, you can use

    import sys

    try:
    raise "foo"
    except:
    print sys.exc_info()[1]


    to get a hold on what's being caught by the exception handler.

    Diez
     
    Diez B. Roggisch, Feb 24, 2006
    #2
    1. Advertising

  3. Odd-R.

    Rene Pijlman Guest

    Odd-R.:
    >I thought Exception would catch all exceptions.


    Try this:

    import sys

    try:
    pass # your code here
    except:
    e = sys.exc_value()

    Either to catch everything, or to get a hold on e.

    --
    René Pijlman
     
    Rene Pijlman, Feb 24, 2006
    #3
    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. Babu
    Replies:
    1
    Views:
    2,919
    Jim Gibson
    Mar 10, 2005
  2. Mark Tarver
    Replies:
    22
    Views:
    1,308
    J Kenneth King
    Apr 26, 2009
  3. Peter
    Replies:
    34
    Views:
    1,939
    James Kanze
    Oct 17, 2009
  4. VSK
    Replies:
    0
    Views:
    248
  5. Iñaki Baz Castillo
    Replies:
    1
    Views:
    188
    Iñaki Baz Castillo
    Apr 15, 2008
Loading...

Share This Page