Catching a non-Exception object (KeyboardInterrupt)

Discussion in 'Python' started by Michael Goerz, Feb 4, 2008.

  1. Hi,

    when I try to catch ctrl+c with

    except KeyboardInterrupt:

    pychecker tells me

    Catching a non-Exception object (KeyboardInterrupt)

    It works fine, but the message indicates that it's not completely clean.
    How should I write the exception correctly?

    Thanks,
    Michael
     
    Michael Goerz, Feb 4, 2008
    #1
    1. Advertising

  2. Michael Goerz <4ward.com> writes:

    > when I try to catch ctrl+c with
    >
    > except KeyboardInterrupt:
    >
    > pychecker tells me
    >
    > Catching a non-Exception object (KeyboardInterrupt)


    Looks like a pychecker bug. It might be confused by KeyboardInterrupt
    being derived not from Exception, but from BaseException.
     
    Hrvoje Niksic, Feb 4, 2008
    #2
    1. Advertising

  3. Michael Goerz

    Duncan Booth Guest

    Hrvoje Niksic <> wrote:

    > Michael Goerz <4ward.com> writes:
    >
    >> when I try to catch ctrl+c with
    >>
    >> except KeyboardInterrupt:
    >>
    >> pychecker tells me
    >>
    >> Catching a non-Exception object (KeyboardInterrupt)

    >
    > Looks like a pychecker bug. It might be confused by KeyboardInterrupt
    > being derived not from Exception, but from BaseException.
    >


    There's a patch for this see:
    https://thomas.apestaart.org/thomas/trac/changeset/938?format=diff&new=938
    but it looks like pychecker isn't being maintained because nothing has
    changed for more than 2 years.
     
    Duncan Booth, Feb 4, 2008
    #3
  4. En Mon, 04 Feb 2008 11:53:52 -0200, Michael Goerz
    <4ward.com> escribi�:

    > when I try to catch ctrl+c with
    >
    > except KeyboardInterrupt:
    >
    > pychecker tells me
    >
    > Catching a non-Exception object (KeyboardInterrupt)
    >
    > It works fine, but the message indicates that it's not completely clean.
    > How should I write the exception correctly?


    Your code is right; the latest official release of pychecker doesn't
    support Python 2.5.
    The exception hierarchy has changed a little, now you have BaseException
    -> Exception -> all standard exceptions. KeyboardInterrupt and SystemExit
    are now direct subclasses of BaseException, not of Exception.
    According to the changelog [1] the development version does support 2.5

    [1]
    http://pychecker.cvs.sourceforge.net/pychecker/pychecker/CHANGELOG?view=markup

    --
    Gabriel Genellina
     
    Gabriel Genellina, Feb 4, 2008
    #4
    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. PantherSE
    Replies:
    0
    Views:
    383
    PantherSE
    May 16, 2005
  2. darren kirby
    Replies:
    1
    Views:
    542
    Diez B. Roggisch
    Nov 27, 2005
  3. Replies:
    3
    Views:
    836
    Donn Cave
    Nov 28, 2005
  4. darren kirby
    Replies:
    1
    Views:
    345
  5. Tony Nelson

    Trace KeyboardInterrupt exception?

    Tony Nelson, Jun 13, 2006, in forum: Python
    Replies:
    4
    Views:
    515
    Tony Nelson
    Jun 15, 2006
Loading...

Share This Page