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

  • Home
  • SEARCH
  • 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 718229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:30:10+00:00 2026-05-14T05:30:10+00:00

When I get a runtime exception from the standard library, it’s almost always a

  • 0

When I get a runtime exception from the standard library, it’s almost always a problem in my code and not in the library code. Is there a way to truncate the exception stack trace so that it doesn’t show the guts of the library package?

For example, I would like to get this:

Traceback (most recent call last):
  File "./lmd3-mkhead.py", line 71, in <module>
    main()
  File "./lmd3-mkhead.py", line 66, in main
    create()
  File "./lmd3-mkhead.py", line 41, in create
    headver1[depotFile]=rev
TypeError: Data values must be of type string or None.

and not this:

Traceback (most recent call last):
  File "./lmd3-mkhead.py", line 71, in <module>
    main()
  File "./lmd3-mkhead.py", line 66, in main
    create()
  File "./lmd3-mkhead.py", line 41, in create
    headver1[depotFile]=rev
  File "/usr/anim/modsquad/oses/fc11/lib/python2.6/bsddb/__init__.py", line 276, in __setitem__
    _DeadlockWrap(wrapF)  # self.db[key] = value
  File "/usr/anim/modsquad/oses/fc11/lib/python2.6/bsddb/dbutils.py", line 68, in DeadlockWrap
    return function(*_args, **_kwargs)
  File "/usr/anim/modsquad/oses/fc11/lib/python2.6/bsddb/__init__.py", line 275, in wrapF
    self.db[key] = value
TypeError: Data values must be of type string or None.

update: added an answer with the code, thanks to the pointer from Alex.

  • 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-05-14T05:30:10+00:00Added an answer on May 14, 2026 at 5:30 am

    Thanks to the pointer from Alex, here’s teh codez:

    def trimmedexceptions(type, value, tb, pylibdir=None, lev=None):
        """trim system packages from the exception printout"""
        if pylibdir is None:
            import traceback, distutils.sysconfig
            pylibdir = distutils.sysconfig.get_python_lib(1,1)
            nlev = trimmedexceptions(type, value, tb, pylibdir, 0)
            traceback.print_exception(type, value, tb, nlev)
        else:
            fn = tb.tb_frame.f_code.co_filename
            if tb.tb_next is None or fn.startswith(pylibdir):
                return lev
            else:
                return trimmedexceptions(type, value, tb.tb_next, pylibdir, lev+1)
    
    import sys
    sys.excepthook=trimmedexceptions
    
    # --- test code ---
    
    def f1(): f2()
    def f2(): f3()
    def f3():
        import xmlrpclib
        proxy = xmlrpclib.ServerProxy('http://nosuchserver')
        proxy.f()
    
    f1()
    

    Which yields this stack trace:

    Traceback (most recent call last):
      File "./tsttraceback.py", line 47, in <module>
        f1()
      File "./tsttraceback.py", line 40, in f1
        def f1(): f2()
      File "./tsttraceback.py", line 41, in f2
        def f2(): f3()
      File "./tsttraceback.py", line 45, in f3
        proxy.f()
    gaierror: [Errno -2] Name or service not known
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 414k
  • Answers 414k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There's no real built-in support for what you want. If… May 15, 2026 at 8:35 am
  • Editorial Team
    Editorial Team added an answer Use type T1 = ... and T2 = ... to… May 15, 2026 at 8:35 am
  • Editorial Team
    Editorial Team added an answer You might take a look at this article on the… May 15, 2026 at 8:35 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.