How to get your hands on exception object caught by default ipython exception handler?

Viewed 3845

Suppose I'm running some code interactively in IPython and it produces an uncaught exception, like:

In [2]: os.waitpid(1, os.WNOHANG)
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-2-bacc7636b058> in <module>()
----> 1 os.waitpid(1, os.WNOHANG)

OSError: [Errno 10] No child processes

This exception is now intercepted by the default IPython exception handler and produces an error message. Is it possible somehow to extract the exception object that was caught by IPython?

I want to have the same effect as in:

# Typing this into IPython prompt:
try:
    os.waitpid(1, os.WNOHANG)
except Exception, exc:
    pass
# (now I can interact with "exc" variable)

but I want it without this try/except boilerplate.

1 Answers
Related