Castrated traceback in sys.exc_info()

Pascal Chambon chambon.pascal at wanadoo.fr
Mon Mar 22 19:20:39 CET 2010


Gabriel Genellina a écrit :
>
> En Wed, 17 Mar 2010 09:42:06 -0300, Pascal Chambon 
> <chambon.pascal at gmail.com> escribió:
>
>> traceback functions indeed allow the manipulation of exception 
>> tracebacks,
>> but the root problem is that anyway, since that traceback is incomplete,
>> your "traceback.format_exc().splitlines()" will only provide frames for
>> callee (downward) functions, not caller (upward) ones, starting from the
>> exception catching frame.
>
> Either I don't understand what you mean, or I can't reproduce it:
>
>

Allright, here is more concretely the problem :

<code>
import logging

def a(): return b()
def b(): return c()
def c():
    try:
        return d()
    except:
        logging.exception("An error")
   
def d(): raise ValueError

def main():
    logging.basicConfig(level=logging.DEBUG)
    a()
 
main()
</code>

OUTPUT:
 >>>
ERROR:root:An error
Traceback (most recent call last):
  File "C:/Users/Pakal/Desktop/aaa.py", line 7, in c
    return d()
  File "C:/Users/Pakal/Desktop/aaa.py", line 11, in d
    def d(): raise ValueError
ValueError
 >>>


As you see, the traceback only starts from function c, which handles the 
exception.
It doesn't show main(), a() and b(), which might however be (and are, in 
my case) critical to diagnose the severity of the problem (since many 
different paths would lead to calling c()).

So the question is : is that possible to enforce, by a way or another, 
the retrieval of the FULL traceback at exception raising point, instead 
of that incomplete one ?

Thank you for your help,
regards,

Pascal





More information about the Python-list mailing list