Bdfy
Bdfy

Reputation: 24621

python exceptions: how to print all debug info for nested try?

I have code:

try:
    print test.qwerq]
    try:
        print test.sdqwe]
    except:
        pass
except:
   pass

How to print debug info for all errors in nested try ?

Upvotes: 0

Views: 627

Answers (1)

nmichaels
nmichaels

Reputation: 50951

Re-raise exceptions.

try:
    print test[qwerq]
    try:
        print test[qwe]
    except:
        # Do something with the exception.
        raise
except:
   # Do something here too, just for fun.
   raise

It should be noted that in general you don't want to do this. You're better off not catching the exception if you're not going to do anything about it.

If you want to just print the call stack and not crash, look into the traceback module.

Upvotes: 7

Related Questions