簡體   English   中英

如何捕獲 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)時起作用。 但是當我使用無效參數時,我得到錯誤:

在拋出“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;
      }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM