3

See the title of this question. I want to play with the exception raised in the last command. _ didn't help me. Is there anything like that?

Achimnol
  • 1,551
  • 3
  • 19
  • 31
  • Could you provide any code or error traceback or anything we can read to understand what you're talking about? – S.Lott Jul 03 '09 at 12:15

2 Answers2

5

Do this:

import sys
sys.exc_info()

It will give you information about the exception. It's a tuple containing the exception type, the exception instance and a traceback object.

Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251
  • 2
    sys.last_value will not work in 3.0, sys.exc_info() will work on 3.0 and 2.x – Anurag Uniyal Jul 03 '09 at 07:52
  • sys.last_value works in 2.7 and according to the documentation, it's still there in Python 3.3. However sys.exc_info() won't work outside of an `except` block. – jd. Apr 27 '12 at 12:18
0

If your 'interactive' happens within Jupyter, check this > Jupyter magic to handle notebook exceptions

It is just beautiful.

If you want to add a sound > Jupyter / Colab : Play sound with any error in any cell + Play sound after completing long running cells

Rub
  • 2,071
  • 21
  • 37