AttributeError: last_traceback

Guido van Rossum guido at python.org
Fri Aug 31 17:28:47 EDT 2001


Curtis Jensen <cjensen at bioeng.ucsd.edu> writes:

> I have a section of code similar to this:
> 
>     try:
>       exec(  <SOMETHING> )
>     except:
>       print traceback.print_exc()
> 
> This is so exceptions don't bring down my program.  And some errors, I
> can ignor.  However, some errors I need to debug.  For the errors I want
> to debug, I'd like to uses "pdb.pm()"  however, I always get
> "AttributeError: last_traceback" with "pdb.pm()"  Understandably, this
> is because noe exception was loged, because I caught it.  
> 
> Is there a way I can catch exceptions and still use pdb.pm()?

  import sys
  try:
      exec <SOMETHING>
  except:
      sys.last_type, sys.last_value, sys.last_traceback = sys.exc_info()
      print traceback.print_exc()

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-list mailing list