12

Very simple minimal example:

if __name__ == '__main__':
    print("Still ok")
    raise Exception("Dummy exception")
    print("End of Program")

I get this output when running it in the PyCharm 2019.2 debugger with Python 3.6:

/usr/bin/python3.6 /home/[...]/pycharm-community-2019.2/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 46850 --file /home/[...]/test_traceback.py
pydev debugger: process 18394 is connecting

Connected to pydev debugger (build 192.5728.105)
Still ok

At this point the debugger breaks the execution flow but no Traceback and Exception message is shown in the Debugger console. If I run the same in PyCharm 2018.1 it does show these right when the breakpoint is hit.

When I hit Continue, I get the desired output, but then I can't run code in the debugging context anymore because the process ends:

Traceback (most recent call last):
  File "/home/[...]/pycharm-community-2019.2/helpers/pydev/pydevd.py", line 2060, in <module>
    main()
  File "/home/[...]/pycharm-community-2019.2/helpers/pydev/pydevd.py", line 2054, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/home/[...]/pycharm-community-2019.2/helpers/pydev/pydevd.py", line 1405, in run
    return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
  File "/home/[...]/pycharm-community-2019.2/helpers/pydev/pydevd.py", line 1412, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/home/[...]/pycharm-community-2019.2/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/[...]/test_traceback.py", line 4, in <module>
    raise Exception("Dummy exception")
Exception: Dummy exception

Process finished with exit code 1

My Breakpoint configuration:

Breakpoint config

3
  • But... that's how it works? It throws an error, you pause. Traceback in the console is literally the last thing handler does. But you pause it before handler starts. Your breakpoint is for the exception, not for the inside of the handler (where it prints the traceback) or something like "stop just before you exit".
    – h4z3
    Commented Aug 29, 2019 at 8:43
  • 2
    This article might be useful: intellij-support.jetbrains.com/hc/en-us/community/posts/… Short form: examine the __exception__ variable to see which exception was thrown and its fields. Commented Aug 29, 2019 at 8:47
  • @h4z3 The behavior I expect was the one I was used to from older PyCharm versions. To confirm, I just downloaded a fresh PyCharm 2018.1 executed the program and it did stop at the exception, printed the exception message and traceback and still let me debug it in place.
    – Philipp F
    Commented Aug 29, 2019 at 13:38

2 Answers 2

4
+50

It works on PyCharm (Community) 2019.1.4:

Img0

Seems like you ran into a (regression) bug:

which affects v2019.2.1, and is scheduled to be fixed in v2019.2.3.

To get past this issue, you'll have to either:

  • Wait for v2019.2.3 (or any other that has the fix) to be released, and switch to that (might want to (periodically) check [JetBrains.Blog]: Release Announcements)

  • Revert to a (previous) version which is not affected by the bug (as I already mentioned: 2019.1.4)

As a note: when running into this kinds of situations, in the (unlikely) case that the problem is not yet known, one could take matters into their own hands, do some debugging, and fix the problem (maybe submit a patch with the fix to JetBrains). Check [SO]: Run / Debug a Django application's UnitTests from the mouse right click context menu in PyCharm Community Edition? for an example.



Update #0

Installed (on 20190930) latest patch (v2019.2.3), and the traceback is present in PyCharm's console (so, the bug is fixed).

3
  • Thanks. This is the correct answer I was looking for.
    – Philipp F
    Commented Sep 9, 2019 at 8:18
  • You're welcome!. Mondays when I reboot my laptop, I check for updates for my currently installed apps, and I usually update them. Thanks to your question I didn't upgrade PyCharm. and I won't, till this will be fixed. It doesn't bother me very much (as I don't rely much on this feature), but still :) .
    – CristiFati
    Commented Sep 9, 2019 at 9:03
  • The fix is now integrated in the EAP version 2019.3 EAP build 193.3519.27 and hence will also be part of PyCharm v2019.3
    – Philipp F
    Commented Sep 23, 2019 at 6:30
0

did you check your whitespaces at start of each executable line? one time it occured to me was fixed after just correcting the whitespaces.

1
  • Definitely doesn't have to do anything with whitespace. I can run the exact same program in an older PyCharm and it works as expected.
    – Philipp F
    Commented Aug 29, 2019 at 13:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.