0

Is there a way to start the debugger automatically in Eclipse PyDev on an error or uncaught exception, in order to examine variables? Currently I need to set a breakpoint at the error and re-launch the code, wasting time while getting there again.

Vanilla Python and Ipython has some ways to do it, as discussed in:

Starting python debugger automatically on error

Maybe some of these can be adapted? %pdb does not work.

takbal
  • 183
  • 1
  • 6

1 Answers1

1

You have some choices here...

You can ask the debugger to stop on uncaught exceptions.

i.e.: open the debug perspective then choose in the menu: Pydev > manage exception breakpoints, select BaseException and then select to suspend on uncaught exceptions (so, when you have some unhandled exception if you're running in the debugger it'll pause).

Still, in this case you have to be running in the debugger for it to stop... if you want to do a regular run (i.e.: started without the debugger), you can do the try..except as you linked in Starting python debugger automatically on error but for the except clause use a pydevd programmatic breakpoint.

Note: for that you can do a code-completion on pydevd in the editor

-- it should expand to something as:

import sys;sys.path.append(r'<path to pydevd src>')
import pydevd;pydevd.settrace()

-- see: http://www.pydev.org/manual_adv_remote_debugger.html for details on the remote debugger.

In this case, make sure that you always start the remote debugger to listen for the connection too (open the preferences > PyDev > Debug > Remote debugger server activation > Keep always on).

Fabio Zadrozny
  • 24,814
  • 4
  • 66
  • 78
  • Thank you. I usually call my functions from the interactive console, because managing debug configs in Eclipse is tedious, and you also need to make the module work from the command line. I place a breakpoint anywhere, then launch a debug console when it is hit. The console seem to follow the frame of all breakpoints from there on. It would be ideal if Exception Breakpoints could work for this workflow as well. An exception calling pydevd.settrace() seem to trigger the debugger indeed, but I can only obtain the frame of the exception handler, but not the frame where the exception occurred. – takbal Dec 18 '19 at 15:42
  • If you do a `raise` after the `pydevd.settrace()` and enable the unhandled exception breakpoint, I think it should work (maybe you can do `pydevd.settrace(suspend=False)` so that it doesn't suspend there and just starts the debugger machinery -- that way it should only stop when actually showing the unhandled exception). – Fabio Zadrozny Dec 18 '19 at 20:14