Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I recover an older traceback in python? (eg second to last)
    primarykey
    data
    text
    <p>I'm sure you found yourself in this situation, and I suspect there is no way out of this. Suppose you run some python code that raises an exception, then you want to look into it but accidentally raise <strong>another</strong> exception while doing so. If you try postmortem debugging now, you'll see the traceback of the latter exception. My question is, is the former lost forever?</p> <p>Example:</p> <pre><code>def my_buggy_function(x): y = x + 1 raise RuntimeError </code></pre> <p>Step 1: I raise an error and I want to debug it</p> <pre><code>my_buggy_function(1) --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) /home/user/&lt;ipython-input-1-430423eaff77&gt; in &lt;module&gt;() 3 raise RuntimeError 4 ----&gt; 5 my_buggy_function(1) /home/user/&lt;ipython-input-1-430423eaff77&gt; in my_buggy_function(x) 1 def my_buggy_function(x): 2 y = x + 1 ----&gt; 3 raise RuntimeError 4 5 my_buggy_function(1) RuntimeError: </code></pre> <p>Step 2: I try to debug the error but accidentally raise another one (in this case, I did not load pdb)</p> <pre><code> pdb.pm() #Oops.. --------------------------------------------------------------------------- NameError Traceback (most recent call last) /home/user/&lt;ipython-input-2-619d77b83f20&gt; in &lt;module&gt;() ----&gt; 1 pdb.pm() NameError: name 'pdb' is not defined import pdb </code></pre> <p>Step 3: Now the traceback gives me the last error, and the second to last is lost.</p> <pre><code> pdb.traceback.print_last() Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2538, in run_code exec code_obj in self.user_global_ns, self.user_ns File "&lt;ipython-input-1-619d77b83f20&gt;", line 1, in &lt;module&gt; pdb.pm() NameError: name 'pdb' is not defined </code></pre> <p>What if I want to access y in the second-to-last traceback, is it lost forever?</p> <p>Note: I'm using ipython/ipdb in case it matters </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload