Re: Understanding and dealing with an exception

Discussion in 'Python' started by Terry Reedy, Oct 14, 2012.

  1. Terry Reedy

    Terry Reedy Guest

    On 10/14/2012 4:20 AM, Mark Lawrence wrote:

    > 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.


    There are some bare except:s in the stdlib, that adding another is
    frowned on and removing one is smiled upon.

    However:
    >>> StandardError

    Traceback (most recent call last):
    File "<pyshell#0>", line 1, in <module>
    StandardError
    NameError: name 'StandardError' is not defined

    Try:
    >>> Exception

    <class 'Exception'>

    This catches everything except a few things like Keyboard Interrupt that
    you normally should not catch.

    >>> BaseException

    <class 'BaseException'>

    This catches everything, but signals that doing so is probably intentional.

    --
    Terry Jan Reedy
     
    Terry Reedy, Oct 14, 2012
    #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. Chris Angelico
    Replies:
    0
    Views:
    188
    Chris Angelico
    Oct 14, 2012
  2. Chris Angelico
    Replies:
    0
    Views:
    201
    Chris Angelico
    Oct 14, 2012
  3. Chris Angelico
    Replies:
    0
    Views:
    236
    Chris Angelico
    Oct 14, 2012
  4. Mark Lawrence
    Replies:
    0
    Views:
    154
    Mark Lawrence
    Oct 14, 2012
  5. Mark Lawrence
    Replies:
    0
    Views:
    203
    Mark Lawrence
    Oct 14, 2012
Loading...

Share This Page