Exception not captured

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Miki Tebeka

    #1

    Exception not captured

    Hello All,

    Can someone please explain how is the following code fragment possible?
    (If you're interested I can place the whole project somewhere).

    def checkout(dest, log):
    '''Get latest version from SCM

    client - SCM client to use
    dest - Destination directory
    '''
    try:
    SCM.checkout(de st, log)
    except SCMError, e:
    raise NightlyError("C heckout")
    except Exception, e:
    import inspect
    file = inspect.getsour cefile(e.__clas s__)
    line = inspect.getsour celines(e.__cla ss__)[1]
    print "%s:%d" % (file, line)
    file = inspect.getsour cefile(SCMError )
    line = inspect.getsour celines(SCMErro r)[1]
    print "%s:%d" % (file, line)
    print SCMError is e.__class__
    raise SystemExit

    I get to the second "except" clause, and the printout is:
    /home/mikit/work/nightly/scm/common.py:3
    /home/mikit/work/nightly/scm/common.py:3
    False

    How is this possible?
    Bye.
    --
    ------------------------------------------------------------------------
    Miki Tebeka <miki.tebeka@zo ran.com>

    The only difference between children and adults is the price of the toys

  • Peter Otten

    #2
    Re: Exception not captured

    Miki Tebeka wrote:
    [color=blue]
    > Hello All,
    >
    > Can someone please explain how is the following code fragment possible?
    > (If you're interested I can place the whole project somewhere).
    >
    > def checkout(dest, log):
    > '''Get latest version from SCM
    >
    > client - SCM client to use
    > dest - Destination directory
    > '''
    > try:
    > SCM.checkout(de st, log)
    > except SCMError, e:
    > raise NightlyError("C heckout")
    > except Exception, e:
    > import inspect
    > file = inspect.getsour cefile(e.__clas s__)
    > line = inspect.getsour celines(e.__cla ss__)[1]
    > print "%s:%d" % (file, line)
    > file = inspect.getsour cefile(SCMError )
    > line = inspect.getsour celines(SCMErro r)[1]
    > print "%s:%d" % (file, line)
    > print SCMError is e.__class__
    > raise SystemExit
    >
    > I get to the second "except" clause, and the printout is:
    > /home/mikit/work/nightly/scm/common.py:3
    > /home/mikit/work/nightly/scm/common.py:3
    > False
    >
    > How is this possible?[/color]

    Some kind of duplicate import, maybe? E.g.:
    [color=blue][color=green][color=darkred]
    >>> import sys
    >>> import inspect
    >>> getsource = inspect.getsour ce
    >>> del sys.modules["inspect"]
    >>> import inspect
    >>> getsource is inspect.getsour ce[/color][/color][/color]
    False

    Peter

    Comment

    • Roy Smith

      #3
      Re: Exception not captured

      In article <mailman.512.11 05450018.22381. python-list@python.org >,
      Miki Tebeka <miki.tebeka@zo ran.com> wrote:
      [color=blue]
      > print SCMError is e.__class__
      > raise SystemExit
      >
      > I get to the second "except" clause, and the printout is:
      > /home/mikit/work/nightly/scm/common.py:3
      > /home/mikit/work/nightly/scm/common.py:3
      > False
      >
      > How is this possible?[/color]

      I suspect you meant to do:

      print "SCMError is", e.__class__

      The way you have it now, it's printing out the result of the "is"
      operator, which tests for identity.

      Comment

      Working...