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 72469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:02:58+00:00 2026-05-10T20:02:58+00:00

This is a question I have wondered about for quite some time, yet I

  • 0

This is a question I have wondered about for quite some time, yet I have never found a suitable solution. If I run a script and I come across, let’s say an IndexError, python prints the line, location and quick description of the error and exits. Is it possible to automatically start pdb when an error is encountered? I am not against having an extra import statement at the top of the file, nor a few extra lines of code.

  • 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. 2026-05-10T20:02:59+00:00Added an answer on May 10, 2026 at 8:02 pm

    You can use traceback.print_exc to print the exceptions traceback. Then use sys.exc_info to extract the traceback and finally call pdb.post_mortem with that traceback

    import pdb, traceback, sys  def bombs():     a = []     print a[0]  if __name__ == '__main__':     try:         bombs()     except:         extype, value, tb = sys.exc_info()         traceback.print_exc()         pdb.post_mortem(tb) 

    If you want to start an interactive command line with code.interact using the locals of the frame where the exception originated you can do

    import traceback, sys, code  def bombs():     a = []     print a[0]  if __name__ == '__main__':     try:         bombs()     except:         type, value, tb = sys.exc_info()         traceback.print_exc()         last_frame = lambda tb=tb: last_frame(tb.tb_next) if tb.tb_next else tb         frame = last_frame().tb_frame         ns = dict(frame.f_globals)         ns.update(frame.f_locals)         code.interact(local=ns) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about this question . I posted a reply there but
I've always wondered about this ... and thankfully, now have a good environment of
Inspired by this question How can I force GDB to disassemble? I wondered about
I have wondered for a while about the feasibility of having Java run on
Had a question that I've often wondered about. Is it better to have multiple
The responses I've got to this question have solved the problem I had in
This question follows on from this vim search question I have a setting in
I have this question: Does implementing a custom MembershipProvider class needs you to implement
Following on from this question I now have code that can attach to a
I am new to C and i have this question. why does the following

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.