Cython -Python异常传播C 例外
Propagating c++ exception to cython - python exception
我有Cython 0.17.1
的问题我的功能会抛出 std::runtime_error
如果文件不存在,我想以某种方式传播此例外。
void loadFile(const string &filename)
{
// some code, if filename doesn't exists
throw std::runtime_error( std::string("File doesn't exists" ) );
}
和右包装后的Cython:
try:
loadFile(myfilename)
except RuntimeError:
print "Can't load file"
但是总是忽略了这个例外,我如何从python捕获C 例外?
您是否正在声明与外部的异常处理?您应该阅读有关C 异常处理的信息:http://docs.cython.org/src/userguide/wrapping_cplusplus.html#exceptions
基本上,您需要执行以下操作:
cdef extern from "some_file.h":
cdef int foo() except +
将您的函数声明为except +
,请参见http://docs.cython.org/src/src/userguide/wrapping_cplusplus.html#exceptions
相关文章:
- 将 ctypes 与 tesserac-ocr 一起使用的例外 TessPageIteratorBoundingBox.
- 为什么程序员同时使用 std::bad_alloc 和 std::exception.是否 std::例外 仅是不够的
- 继承 C++11 中的例外?
- C++ - 为什么这有很强的例外保证?
- 与 boost::locale 关于"ß"大写的例外行为混淆
- Chrome GN 例外已禁用
- cmake 使用 find_package 传播依赖项
- 如何在 x64 上"stack oveflow"例外
- 使用 stod() 转换小数点后字母的字符串时没有例外
- 组合"%"和可选后缀时,自动属性传播有时不起作用
- 跨目标传播库依赖项
- 该标准是否说明了例外和不同调用约定的共存
- 例外:'Access violation reading location'
- 为什么复制省略是"好像"规则的一个例外
- 张量流 c++ API 是否支持反向传播的自动微分?
- 为什么我在此删除中有例外?
- 常量字符*是否有任何例外?
- 升级到G++4.8-exception_ptr.h不支持异常传播
- Cython -Python异常传播C 例外
- 任何方式来取消信号传播在升压信号s2没有例外