dropping into pdb on an exception

Discussion in 'Python' started by Jon Perez, Jun 9, 2004.

  1. Jon Perez

    Jon Perez Guest

    How do you set up pdb such that you will automatically
    get dropped into its prompt if an unanticipated exception
    occurs in a script you are using?

    ASPN Python cookbook gives you the following method
    which you can add to your script and hook into sys.excepthook.
    But is there a way to do it without adding stuff to your
    script? (It's okay if this means having to invoke the script
    from within pdb, but #1, I don't know how to get it stay inside
    pdb in the case of an /unanticipated/ exception. And #2, I
    don't know how to pass [the equivalent of] command-line
    arguments to a script invoked from within pdb.)



    def info(type, value, tb):
    if hasattr(sys, 'ps1') or not sys.stderr.isatty():
    # we are in interactive mode or we don't have a tty-like
    # device, so we call the default hook
    sys.__excepthook__(type, value, tb)
    else:
    import traceback, pdb
    # we are NOT in interactive mode, print the exception...
    traceback.print_exception(type, value, tb)
    print
    # ...then start the debugger in post-mortem mode.
    pdb.pm()

    sys.excepthook = info
    Jon Perez, Jun 9, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. luna
    Replies:
    1
    Views:
    324
    =?Utf-8?B?VHUtVGhhY2g=?=
    Feb 13, 2004
  2. Jon Perez
    Replies:
    0
    Views:
    275
    Jon Perez
    Jun 6, 2004
  3. Jon Perez
    Replies:
    13
    Views:
    489
    Jon Perez
    Jun 14, 2004
  4. Amit Gupta

    using pdb and catching exception

    Amit Gupta, Dec 1, 2007, in forum: Python
    Replies:
    5
    Views:
    415
    R. Bernstein
    Dec 6, 2007
  5. Josef Moellers

    Palm::PDB: How to compose a PDB?

    Josef Moellers, Aug 16, 2007, in forum: Perl Misc
    Replies:
    0
    Views:
    142
    Josef Moellers
    Aug 16, 2007
Loading...

Share This Page