Setup:
- Python 3.5.3 |Continuum Analytics, Inc.| (默认,2017 年 3 月 6 日 12:15:08)
- Mac OS X 10.13.1
Problem:
我已经下载了以下 R 脚本https://github.com/daleroberts/heston/blob/master/heston.r https://github.com/daleroberts/heston/blob/master/heston.r我使用 RPy2 包通过 Python 反复调用其中的函数之一。现在,对于输入 R 函数的一些输入,R 返回以下错误:
rpy2.rinterface.RRuntimeError:集成错误(PIntegrand,lower =
0, upper = Inf, lambda, vbar, eta, : 检测到舍入误差
我该如何在Python中捕捉这个RuntimeError?
The RRuntimeError
源自Exception
所以你应该能够像捕获任何其他异常一样捕获它。
try:
# your code
except rpy2.rinterface.RRuntimeError:
# handle exception
在 rpy2 v3.0 及以上版本, RRuntimeError
似乎已被移动到其他地方(参见示例代码来自文档 https://rpy2.github.io/doc/v3.0.x/html/introduction.html?highlight=rruntimeerror#graphics-and-plots)所以你可能需要使用这个:
try:
# your code
except rpy2.rinterface_lib.embedded.RRuntimeError:
# handle exception
更多相关内容:https://docs.python.org/3/tutorial/errors.html#handling-exceptions https://docs.python.org/3/tutorial/errors.html#handling-exceptions
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)