例外未在node.js附加中捕获
exception not caught in node.js add-on
我目前正在根据armadillo线性代数库的对象包装编写包装程序类。我已经注意到,当armadillo发出异常时,即使我尝试处理例外,也不会捕获附加代码:
if(args[0].isString()){
try{
std::string s(*v8::String::AsciiValue(args[0]->ToString()));
MatrixWrap* matrix = new MatrixWrap(s);
matrix->Wrap(args.This());
}catch(exception& e){
cout << "caught exception" << endl; // this code is never called.
}
}
下面给出了相应的相应构造函数(_matrix是Arma :: Mat的一个实例,如果字符串未正确格式化,则引发异常):
MatrixWrap::MatrixWrap(string s):_matrix(s){
}
运行代码时,我将获得以下输出:
> var arma = require('./build/Release/armadillo');
> var matrix = new arma.Matrix('1 0; 0 1');
> matrix.print();
1.0000 0
0 1.0000
> var B = new arma.Matrix('1 0; 0');
error: Mat::init(): inconsistent number of columns in given string
libc++abi.dylib: terminate called throwing an exception
Abort trap: 6
尽管捕获子句
而不是 catch(异常&amp; e),尝试使用 catch(...),它应该捕获所有例外。p>根据错误,Armadillo抛出STD :: LOGIC_ERROR,STD :: BAD_ALLOC或STD :: RUNTIME_ERROR
修改的构建脚本以启用异常处理:
{
"targets": [
{
'target_name': 'armadillo',
'sources':[ "src/addon.cpp", "src/MatrixWrap.cpp"],
'link_settings': {
'libraries': ['-larmadillo']
},
'cflags': ['-fexceptions'],
'cflags_cc': ['-fexceptions']
}
]
}
相关文章:
- 在 ubuntu 上安装 node js pulsar 客户端
- Node.js fs.open() 在尝试打开 4 个以上的命名管道 (FIFO) 后挂起
- 在 node.js 中将缓冲区从 C++ 转换为 UTF-8 字符串
- 使用 Node.js N-API 调用 C 函数时,不会显示预期的输出
- 如何使用 v8 本机插件将 C++ 数组交付到 Node.js
- C++ 和 node.js 之间的 RSA 加密
- node.js Nan:在函数C++调用 JavaScript 回调
- 迭代 Napi::对象属性(键)在 Node.js C++ N-API 中
- 上传大文件并解析时使用 Node.js v10.15.1 时出现致命错误
- 如何在 Node.js 中解压缩 c# 打包结构
- 使用 Node.js 调用child_process与从 C 调用子进程并创建C++绑定以从 node.js 调用
- 我们如何访问 Node.js 应用程序之外的内存?
- 我正在c 中的buidling node.js绑定
- 以有效的方式从 Node .js运行 C 或C++代码
- node.js:如何从C 模块中产生
- 如何编译 node.js for CentOS 6.10 (库问题)
- 如何使用 Node.js 开发一个侦听器来接收许多车辆跟踪数据(通过 TCP)
- 使用 N-API 将数据流式传输到 Node.js C++ 插件中
- 在构建Node.js/Node-webkit插件时,通过binding.gyp将.cpp文件编译为Objective-C
- 终端服务器上的IPC,带有一个nw.js/node.js/node-namemodule(C++)