Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make pycharm break on My Exceptions [duplicate]

Possible Duplicate:
break on unhandled exception in pycharm

I'm new in Python and I'm trying to debug my first python program using PyCharm 1.5. I want debugger to break when exception occurs in my code (and only in mine).

For now the situation is following: I use (Ctrl + Shift + F8 ) Dialog to configure debugger and If i set Suspend All = true and All exceptions = true then debugger breaks far too often, for example, it breaks somewhere inside PyCharm 1.5.1\helpers\pydev\pydevd.py which is annoying to skip every time. And if I set any other options then debugger does not break even when exception occurs in my code.

PS: By the way, if I just skip breaks in PyCharm 1.5.1\helpers\pydev\pydevd.py then execution continues without visible errors. So I do not understand why it breaks at all

like image 313
Alex Ilyin Avatar asked Jul 10 '11 18:07

Alex Ilyin


People also ask

How do you skip lines in PyCharm?

If you want to know what it did at that point, right-click and open "evaluate expression" and paste the line you're interested in. insert a condition before 2nd line in order to skip it through conditional logic.

How do you create a breakpoint in Python?

It's easy to set a breakpoint in Python code to i.e. inspect the contents of variables at a given line. Add import pdb; pdb. set_trace() at the corresponding line in the Python code and execute it. The execution will stop at the breakpoint.


1 Answers

One way to tell apart your exceptions from exceptions coming from a library, is to have them derive from a custom class, e.g. if your module is called Foo, you could have

class FooException(Exception):
   pass

and have more specific exceptions derive from this:

class MyMathException(FooException):
   # etc.

Then, in PyCharm, instead of enabling All Exceptions, add FooException to the list of exceptions to break upon.

like image 144
UncleZeiv Avatar answered Oct 14 '22 08:10

UncleZeiv