Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8768311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:02:15+00:00 2026-06-13T17:02:15+00:00

How can i get full traceback in the following case, including the calls of

  • 0

How can i get full traceback in the following case, including the calls of func2 and func functions?

import traceback

def func():
    try:
        raise Exception('Dummy')
    except:
        traceback.print_exc()

def func2():
    func()


func2()

When i run this, i get:

Traceback (most recent call last):
  File "test.py", line 5, in func
    raise Exception('Dummy')
Exception: Dummy

traceback.format_stack() is not what i want, as need traceback object to be passed to a third party module.

I am particularly interested in this case:

import logging


def func():
    try:
        raise Exception('Dummy')
    except:
        logging.exception("Something awful happened!")


def func2():
    func()


func2()

In this case i am getting:

ERROR:root:Something awful happened!
Traceback (most recent call last):
  File "test.py", line 9, in func
    raise Exception('Dummy')
Exception: Dummy
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:02:16+00:00Added an answer on June 13, 2026 at 5:02 pm

    As mechmind answered, the stack trace consists only of frames between the site where the exception was raised and the site of the try block. If you need the full stack trace, apparently you’re out of luck.

    Except that it’s obviously possible to extract the stack entries from top-level to the current frame—traceback.extract_stack manages it just fine. The problem is that the information obtained by traceback.extract_stack comes from direct inspection of stack frames without creating a traceback object at any point, and the logging API requires a traceback object to affect traceback output.

    Fortunately, logging doesn’t require an actual traceback object, it requires an object that it can pass to the formatting routines of the traceback module. traceback doesn’t care either—it only uses two attributes of the traceback, the frame and the line number. So, it should be possible to create a linked list of duck-typed faux-traceback objects and pass it off as the traceback.

    import sys
    
    class FauxTb(object):
        def __init__(self, tb_frame, tb_lineno, tb_next):
            self.tb_frame = tb_frame
            self.tb_lineno = tb_lineno
            self.tb_next = tb_next
    
    def current_stack(skip=0):
        try: 1/0
        except ZeroDivisionError:
            f = sys.exc_info()[2].tb_frame
        for i in xrange(skip + 2):
            f = f.f_back
        lst = []
        while f is not None:
            lst.append((f, f.f_lineno))
            f = f.f_back
        return lst
    
    def extend_traceback(tb, stack):
        """Extend traceback with stack info."""
        head = tb
        for tb_frame, tb_lineno in stack:
            head = FauxTb(tb_frame, tb_lineno, head)
        return head
    
    def full_exc_info():
        """Like sys.exc_info, but includes the full traceback."""
        t, v, tb = sys.exc_info()
        full_tb = extend_traceback(tb, current_stack(1))
        return t, v, full_tb
    

    With these functions in place, your code only requires a trivial modification:

    import logging
    
    def func():
        try:
            raise Exception('Dummy')
        except:
            logging.error("Something awful happened!", exc_info=full_exc_info())
    
    def func2():
        func()
    
    func2()
    

    …to give the expected output:

    ERROR:root:Something awful happened!
    Traceback (most recent call last):
      File "a.py", line 52, in <module>
        func2()
      File "a.py", line 49, in func2
        func()
      File "a.py", line 43, in func
        raise Exception('Dummy')
    Exception: Dummy
    

    Note that the faux-traceback objects are fully usable for introspection—displaying local variables or as argument to pdb.post_mortem()—because they contain references to real stack frames.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How i can get full right name of generic type? For example: This code
Edit: You can get the full source here: http://pastebin.com/m26693 Edit again: I added some
Is there any method I can get the full JSON data from jqGrid when
How can I get the full/absolute URL (e.g. https://example.com/some/path ) in Django without the
i want to get the full address of user programatically using c# how can
Using Scripting.FileSystemObject I can get the full path name of a file, but this
In PHP/Apache I can get the full url and cut it up into parts
hi how can i get full url with & sign RewriteRule category/(.*)$ categories.php?url=$1 [PT,L]
Can get all triples with value null in specific field? All people with date_of_birth
We can get class Class object by 3 methods: MyClass.class obj.getClass Class.forName(className) I don't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.