如何让 pycharm 中断我的异常

发布于 2024-11-19 11:47:56 字数 632 浏览 2 评论 0原文

可能的重复:
pycharm 中未处理的异常中断

我是 Python 新手,我是尝试使用 PyCharm 1.5 调试我的第一个 python 程序。 我希望调试器在我的代码中发生异常时中断(并且仅在我的代码中)。

目前情况如下:我使用 (Ctrl + Shift + F8 ) 对话框来配置调试器,如果我设置 Suspend All = trueAll excepts = true 则调试器会中断例如,它经常在 PyCharm 1.5.1\helpers\pydev\pydevd.py 内部的某个地方中断,每次都跳过这很烦人。如果我设置任何其他选项,那么即使代码中发生异常,调试器也不会中断。

PS:顺便说一句,如果我只是跳过 PyCharm 1.5.1\helpers\pydev\pydevd.py 中的中断,那么执行将继续,不会出现可见错误。所以我根本不明白为什么它会破裂

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南城旧梦 2024-11-26 11:47:56

区分异常和来自库的异常的一种方法是让它们派生自自定义类,例如,如果您的模块称为 Foo,您可以拥有

class FooException(Exception):
   pass

并拥有从此派生的更具体的异常:

class MyMathException(FooException):
   # etc.

然后,在 PyCharm 中,改为要启用 All Exceptions,请将 FooException 添加到要中断的异常列表中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文