nodejs C++ module 在 init 中失败
nodejs C++ module fail in init
我正在编写一个nodejs C++模块,在我的init函数内部,我进行了一次可能会失败的系统调用。 失败时,我希望它向解释器抛出异常来处理,而是得到一个赛段错误。 如何获得正确的行为?
所以例如,我有类似的东西:
//...
void Init(Handle<Object> target) {
if (my_setup_io()==FAIL_CODITION){
ThrowException(Exception::Error(
String::New("Could not init "))); //SEG fault instead of exception
}
target->Set(String::NewSymbol("myFunction"),
FunctionTemplate::New(myFunction)->GetFunction());
}
NODE_MODULE(example, Init)
主要问题是ThrowException
在 JS 中触发异常,但它实际上并没有触发C++异常。这意味着代码将在异常运行后尝试运行Set
。
如果您在安排 JS 抛出后返回,它应该可以正常工作。
void Init(Handle<Object> target) {
if (my_setup_io()==FAIL_CODITION){
ThrowException(Exception::Error(String::New("Could not init ")));
return; // RETURN!
}
target->Set(String::NewSymbol("myFunction"),
FunctionTemplate::New(myFunction)->GetFunction());
}
NODE_MODULE(example, Init)
相关文章:
- 如果没有malloc,链表实现将失败
- 模板参数替换失败,并且未完成隐式转换
- 具有默认模板参数的多态类的模板推导失败
- 视图中的参数推导失败:take_while
- 链接到自行创建的dll失败
- 带有特殊路径部分的"std::filesystem::weakly_canonical"失败
- GetShortPathName在网络驱动器上使用中文文件夹时失败
- gcc和c++17的过载解析失败
- 为什么使用 P/Invoke 调用 dll 时,某些计算机中的 LoadLibrary 失败?
- 在WSL:configure_file上对config_file的每次调用都失败:配置文件时出现问题
- GCC对可能有效的代码抛出init list生存期警告
- 使用 GCC 卸载的 OpenMP 卸载失败,并出现"Ptx assembly aborted due to errors"
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- 链接阶段在Ubuntu上失败,但在MacOS上失败
- 从父数组测试用例构造二叉树失败
- LibGit2 SSH身份验证失败
- 如何让LLDB在成功时退出,在失败时等待
- VS2017,C++包含目录与附加包含目录,子文件夹包含失败-但为什么
- 生成MRPT库时cmake配置失败
- nodejs C++ module 在 init 中失败