如何在 C++ 中捕获 sdbus::Error 异常?

How to catch sdbus::Error exception in c++?

我是 C++ 新手。我正在尝试使用 jni 处理我的 java 应用程序中可能发生的一些错误。这是我的 try/catch 块:

   std::future<lib::LibVector> libVectorFuture;
      
            try {
              libVectorFuture = some::lib::getVector(param1, param2);
          } catch (...) {
              // report problem back to Java.
              jclass Exception = env->FindClass("com/my/MyClientException");
              env->ThrowNew(Exception, "Unable to get result from native getVector(String p1, String p2) method!");
          }

lib::LibVector vector = libVectorFuture.get();

// here I'm using vector

当我使用有效的参数(param1、param2)时它起作用了。但是当我使用无效参数时,我得到错误:

terminate called after throwing an instance of 'sdbus::Error'

和其他一些文字。另外,应用程序停止了。正如我在 catch 块中所理解的那样,我可以捕获任何错误,但它并没有发生。为什么?以及如何捕获任何错误?

终于写出解决方案了。感谢您的回复。

     std::future<lib::LibVector> libVectorFuture;
  
        try {
          libVectorFuture = some::lib::getVector(param1, param2);
          lib::LibVector vector = libVectorFuture.get(); // here I get error
      } catch (...) {
          // report problem back to Java.
          jclass Exception = env->FindClass("com/my/MyClientException");
          env->ThrowNew(Exception, "Unable to get result from native getVector(String p1, String p2) method!");
       return nullptr;
      }