How to enable stopping on unhandled exceptions?

已回答
According to this link
http://youtrack.jetbrains.com/issue/PY-1498

PyCharm is supposed to stop (Break) on unhandled exceptions.

I am unable to find documentation on how to enable this feature.
Would someone please explain how to do this?

Thanks
4
I'm using the IDEA plugin instead of PyCharm, so the names of your menus might be a little different.

Go to Run > View Breakpoints (or press Cmd+Shift+F8/Strg+Shift+F8). This should open the Breakpoints dialog. On the left side there should be a node Python Exception Breakpoints. Make sure that it has its checkboxes checked. Also, you should have Suspend checked. If it isn't, the debugger won't stop on that breakpoint.

You can find more information about this dialog in the Online help.

I hope that helps!
9

Had it set.   Pycharm  still not stopping on exception.

0
Avatar
Permanently deleted user

@Adam Pycharm

Could you post a screenshot of your Breakpoints configuration?

0
Avatar
Permanently deleted user

This does not work in my pycharm professional 2008.1 build #PY-181.4892.64.  I am running remote python to docker if that makes a difference.

0
Avatar
Permanently deleted user

I'd like to add that I'm experiencing the same issue in PyCharm Professional 2018.2.

0

Could you please provide a code sample? Is the exception unhandled? If it's under try/except you have to enable On raise and Ignore library files options on the screenshot above.

0
Avatar
Permanently deleted user

I can't provide a code sample, since I'm working on a proprietary code base. Would a minimal working example (MWE) suffice?

It is not under try/except. It's an unhandled exception.

0

A minimal example would be sufficient indeed, please feel free to create a ticket in our bug tracker https://youtrack.jetbrains.com/issues/PY or send it to me directly at pavel.karateev@jetbrains.com

So the script just exits with a traceback and the debugger doesn't stop the execution, did I understand you correctly?

0
Avatar
Permanently deleted user

Yes, that's correct. I am quite busy today, but I will send you an email with more details on Monday.

0

I'm experiencing a similar issue in IntelliJ. For some reason when I enable the debugger to stop on "any exception", running my program starts to throw `ClassNotFoundException` for some unknown reason, and it stops there before it appears to even a line of code in my program.

0

Has anybody ever found the stop on any exception feature useable?

Whenever I try it, I end up bouncing around in pytest internal exceptions for 15-30 minutes while trying various settings, get tired of wasting my time, and turn it back off.  

I have never been able to get pycharm to quit stopping in library functions.  I don't want my editor polluted by a half dozen library modules and I have no interest in tracing through them.  

As is, my workflow is usually to trace my code and when an exception occurs, I can tell by pycharm bouncing back to the top level call and then into pytest library functions.  I kill it, close all the unwanted editor tabs,  set a breakpoint for the last traceable statement, and try again.  It's 100x faster to keep starting over than to try and get pycharm to break on an exception.

1

Actually, my problem was that I was enabling it to stop on caught exceptions. I wanted only uncaught exceptions.

Perhaps this is what you are seeking as well.

0
Avatar
Permanently deleted user

I have the same problem on handling uncaught exceptions in PyCharm 2018.2.4.

The debugger can stop on breakpoints but cannot stop when an exception is raised and then the program terminates without invoking the debugger.

I attach a screenshot of the code and breakpoints configuration.

Are there any other preferences I have to see?

1

Hey @Emak.

 

Looking at your debugger setup, I'm wondering. At the bottom right of that window, have you tried changing your "Activation policy" settings? Perhaps if you remove the check for "on termination" and add a check for "on raise", this will do what you need?

0
Avatar
Permanently deleted user

I tried "On raise" check instead of "On termination". In that case, the debugger stops on all exceptions including ones raised in starting scripts or modules used by PyCharm. Therefore, I could not reach my exception even though I resumed the program many times.

1

Hi Emak,

It is noted in there that This option may slow down the debugger. Could you please file an issue to https://youtrack.jetbrains.com/issues/PY with your idea.log (Help | Show Log in...) after reproducing the problem?

0
Avatar
Permanently deleted user

I have solved the issue by adding a "--pdb" flag to the "addition arguments" in the Run/Debug configuration. This starts the debugger whenever a uncaught breakpoint is hit.

0
Avatar
Permanently deleted user

I'm having the exact same issue as Emak. Did anyone ever solve it? Okke, I don't have an "addition arguments" field in my Run/Debug Configurations screen. 

0

By additional arguments, Okke probably meant "interpreter options".

Otherwise, I think your best bet would be to create a bug report on https://youtrack.jetbrains.com/issues/PY , describe the issue in detail and attach logs according to https://intellij-support.jetbrains.com/hc/en-us/articles/207241085-Locating-IDE-log-files

 

0

I am having a related problem. My issue is that pycharm is halting in my try catch (so in my handled exception) - which is of course NOT what I want. I was wondering, does anyone know how to have pycharm only halt/break/stop on unhandled exceptions but not on handled ones? Mine is always halting.

Current settings of the breakpoint:

 

btw, cross posted: https://stackoverflow.com/questions/70761481/how-to-stop-pycharms-break-stop-halt-feature-on-handled-exceptions-i-e-only-b and https://intellij-support.jetbrains.com/hc/en-us/community/posts/4415666598546-How-to-stop-PyCharm-s-break-stop-halt-feature-on-handled-exceptions-i-e-only-break-on-python-unhandled-exceptions-

0

How does one do:

 

```

In your link here intellij-support.jetbrains.com/hc/en-us/community/posts/… the poster Okke said they solved this issue adding --pdb to the 'addition arguments', which someone later said they probably meant interpreter options.

```

 

???

0

Still does not work, unfortunately, PyCharm 2022.3.2 (Professional Edition).

Jetbrains should really put some effort into actually fixing this (stopping on unhandled exceptions). The debugger is one of the main advantages over VSCode... 

I expect this is a very common scenario and it should really just work out of the box without having to spend countless hours to get it to work (which apparently many people have to do...).

1

I found the solution to this problem in the documentation, here.

1

Lol that's awesome! So it's just another setting. Can't believe didn't notice that before.

This checkbox should also appear in the "Breakpoints" dialogue, along with the area to set auto breakpoints on exceptions.

 

1

Ok so the problem was that I was running test and jsd solution work as expected!

0

I checked "Drop into debugger on failed tests" and still Pycharm doesn't stop on the exceptions in tests (run in debug mode). For the exception I just copied the example assertion `assert 3 + 2 == 6` from the documentation. My Pycharm version is 2023.1.3.

Update: Tried the same config in a different project and the execution stopped on the exception. So seems to be project related for me.

0

请先登录再写评论。