有个疑问,API发送的命令有错误的时候,为什么不温和一点处理,而是每次直接崩掉

比如我下面的C++ API代码:

int main(int argc, char *argv[]) {
   DBConnection conn;
   bool ret = conn.connect("111.222.3.44", 8503);
   if(!ret){
       cout<<"Failed to connect to the server"<<endl;
       return 0;
   }
   ConstantSP cmdVec = conn.run("add{a+b)");

run的DolphinDB脚本有点问题,在vs2017中执行后api程序就崩了,如下图:
attachments-2021-05-MBT7DxrD60a5c11f38e4b.png

请先 登录 后评论

1 个回答

Juntao Wang

DolphinDB API的处理问题的方式是抛出异常,因此需要try catch一下exception,比如:

    try {
        ConstantSP cmdVec = conn.run("add{a+b)");

    } catch (exception &ex) {
        cout << "Failed to  run  with error: " << ex.what();
        return -1;
    }
请先 登录 后评论