- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果我使用 ipython %pdb
运行代码启用魔法并且代码抛出异常,有什么方法可以告诉代码之后继续执行吗?
例如,假设异常是 ValueError: x=0 not allowed
.我可以在 pdb 中设置 x=1
并允许代码继续(恢复)执行?
最佳答案
我认为您不能事后恢复代码(即实际上引发了异常,触发了调试器的调用)。您可以做的是,在您看到错误的代码中放置断点,这样您就可以更改值,并继续执行程序以避免错误。
给定一个脚本 myscript.py
:
# myscript.py
from IPython.core.debugger import Tracer
# a callable to invoke the IPython debugger. debug_here() is like pdb.set_trace()
debug_here = Tracer()
def test():
counter = 0
while True:
counter += 1
if counter % 4 == 0:
# invoke debugger here, so we can prevent the forbidden condition
debug_here()
if counter % 4 == 0:
raise ValueError("forbidden counter: %s" % counter)
print counter
test()
In [5]: run myscript
1
2
3
> /Users/minrk/dev/ip/mine/myscript.py(14)test()
13 debug_here()
---> 14 if counter % 4 == 0:
15 raise ValueError("forbidden counter: %s" % counter)
# increment counter to prevent the error from raising:
ipdb> counter += 1
# continue the program:
ipdb> continue
5
6
7
> /Users/minrk/dev/ip/mine/myscript.py(13)test()
12 # invoke debugger here, so we can prevent the forbidden condition
---> 13 debug_here()
14 if counter % 4 == 0:
# if we just let it continue, the error will raise
ipdb> continue
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
IPython/utils/py3compat.pyc in execfile(fname, *where)
173 else:
174 filename = fname
--> 175 __builtin__.execfile(filename, *where)
myscript.py in <module>()
17 print counter
18
---> 19 test()
myscript.py in test()
11 if counter % 4 == 0:
12 # invoke debugger here, so we can prevent the forbidden condition
13 debug_here()
14 if counter % 4 == 0:
---> 15 raise ValueError("forbidden counter: %s" % counter)
ValueError: forbidden counter: 8
In [6]:
关于ipython - python pdb : resume code execution after exception caught?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8423637/
这是测试场景: Plugin A 有一个工具类 A.xyz(),它提供了一个方法来抛出 java.util.NoSuchtElementException 插件 B 提供“功能”。 片段 F,它使用
我在java中得到了这段代码: public static void main(String[] args) { try{ Class tryLoadi
如果这个问题听起来很幼稚,请原谅。 在尝试递归打开文件连接后尝试在closeAllConnections()块中使用tryCatch()时,似乎未正确捕获该错误。 这是示例代码: fileOpenRe
过去 2 天我一直在使用 DBUnit,我在比较表格和 xml 文件时遇到了问题。 我粘贴了所有代码并简化了一些代码,以便人们可以尝试找出问题所在。 实际上,执行提取(从 DB2)的方法效果很好。我只
例如: Unhandled error in Deferred: Unhandled Error Traceback (most recent call last): File "/opt/zen
我正在 try catch 在 JavaScript 文件中抛出(并捕获)名称为 FooError 的错误。但是,也有数百个名为 BarError 的错误被抛出和捕获。 当我启用“Pause On C
我正在 dreamhost 上构建 Django +MySQL,但遇到错误消息: 渲染时捕获异常:(1064,“您的 SQL 语法有错误;请检查与您的 MySQL 服务器版本相对应的手册,了解在 ')
我正在尝试编写一个 Google-Appengine 应用程序,当数据存储写入被禁用时,它会很好地失败 目前我的 main() 看起来像这样: def main(): make_datasto
我按照 Kii Cloud 教程创建和归档对象,并尝试将其实现到我自己的应用程序中。它的基本作用是,当用户单击“existingButton”时,它会打开一个新 Activity ,用户可以在其中从图
我正在尝试设置 Django 站点 (OSQA),但无法使其正常工作。 存在一些问题,其中之一是当我尝试查看用户的个人资料时,出现以下异常: 有人可以指出问题可能出在哪里吗? TemplateSynt
情况是我有一个用 C++ 编写的动态库,它由另一个动态库为 Python 包装,该动态库也是用 C++ 编写的(具体而言由 SIP 生成)。第一个动态库定义了一个函数do_raise,它抛出一个异常R
下面的查询... SELECT YEAR(TRY_CAST(m.MetaValue AS DATE)) FROM MetaData m ...导致此错误: String or binary data
以下代码产生错误 DatagramSocket socket = new DatagramSocket(); java.net.* 包含在顶部 错误是未报告的异常java.net.SocketExce
最近我开始用 Java 开发自己的 IRC 客户端/服务器。 NetBeans 说我有一个未处理的 IOException。但是,查看我的代码,我执行了一个捕获 IOException 的 try-c
这个问题已经有答案了: What does "error: unreported exception ; must be caught or declared to be thrown" mean a
我的表单中有一个表格,其中包含下拉列表和隐藏的输入。 JSP:
我正在尝试通过 OpenCV.js 使用面部识别,但是当我调用 CascadeClassifier 对象的 detectMultiScale() 方法时,我收到错误: Uncaught 6446128
我已经为这个程序工作了很长一段时间,我的大脑被炸了。我需要一些正在查看的人的帮助。 我正在尝试制作一个逐行读取文本文件的程序,并将每一行制作成一个ArrayList,这样我就可以访问每个标记。我究竟做
我正在对 fork()、exec() 和相关的 UNIX 调用进行赋值,我需要在其中显示(子)进程的僵尸状态。这是相关的代码片段: pid = vfork(); //used vfork() for
我遇到的问题与 this question 中的问题类似.与那个问题不同的是,我有正确的设置(API key 在 Google 控制台上启用的 list 、 map 和地点 API 中指定)因为代码大
我是一名优秀的程序员,十分优秀!