• <rt id="2awkm"><noscript id="2awkm"></noscript></rt>
      <rt id="2awkm"><noscript id="2awkm"></noscript></rt>
    • <dfn id="2awkm"></dfn>
      <menu id="2awkm"><acronym id="2awkm"></acronym></menu>
      
      
      <rt id="2awkm"></rt><dfn id="2awkm"><code id="2awkm"></code></dfn>
    • <dd id="2awkm"><s id="2awkm"></s></dd>
      <tbody id="2awkm"></tbody>
    • <dfn id="2awkm"></dfn>
      <menu id="2awkm"><noscript id="2awkm"></noscript></menu>

      如何處理運行錯誤

      概述

      Orbbec SDK C++ API 使用 異常機制 實現(xiàn)接口調(diào)用狀態(tài)反饋,當用戶應(yīng)用代碼調(diào)用 API 執(zhí)行過程中出現(xiàn)問題,會向外拋出 ob::Error 類型異常。

      使用說明

      ob::Error 是 Orbbec SDK 自定義的一個異常類,其提供了 4 個接口可以幫助用戶在發(fā)生異常時判斷異常的原因:

      // libobsnesor/hpp/Error.hpp

      /**
      * @brief Get the detailed error logs of SDK internal exceptions.
      * @return A C-style string containing the error message.
      */
      const char *getMessage() const noexcept;

      /**
      * @brief Get the exception type of the error, which can be used to determine which module is abnormal.
      * @return The OBExceptionType enum value.
      */
      OBExceptionType getExceptionType() const noexcept;

      /**
      * @brief Get the name of the error function.
      * @return A C-style string containing the name of the error function.
      */
      const char *getName() const noexcept;

      /**
      * @brief Get the parameter passed to the error interface.
      * @return A C-style string containing the error interface parameter.
      */
      const char *getArgs() const noexcept;

      使用方法如下:

      1. 推薦用戶應(yīng)用代碼在調(diào)用 Orbbec SDK C++ API 時,通過 try-catch 機制捕獲并處理異常:

      try{
        pipe.start(config);
      }catch(ob::Error &e) {
        std::cerr << "Failed to start the pipeline!" << " Exception type:" << e.getExceptionType() << ", name:" << e.getName() << ", message:" << e.getMessage() << std::endl;
      }

      2. 如果函數(shù)內(nèi)包含多個 Orbbec SDK C++ API 調(diào)用,可以在函數(shù)體外部直接捕獲所有異常:

      int main(int argc, char **argv) try {
        // Print the sdk version number, the sdk version number is divided into major version number, minor version number and revision number
        std::cout << "SDK version: " << ob::Version::getMajor() << "." << ob::Version::getMinor() << "." << ob::Version::getPatch() << std::endl;
        // Print sdk stage version
        std::cout << "SDK stage version: " << ob::Version::getStageVersion() << std::endl;

        // Create a Context.
        ob::Context ctx;

        // Query the list of connected devices
        auto devList = ctx.queryDeviceList();

        // Get the number of connected devices
        if(devList->deviceCount() == 0) {
          std::cerr << "Device not found!" << std::endl;
          return -1;
        }

        // Create a device, 0 means the index of the first device
        auto dev = devList->getDevice(0);

        return 0;
      }
      catch(ob::Error &e) {
        std::cerr << "function:" << e.getName() << "\nargs:" << e.getArgs() << "\nmessage:" << e.getMessage() << "\ntype:" << e.getExceptionType() << std::endl;
        exit(EXIT_FAILURE);
      }

      異常類型 

      image.png


      • <rt id="2awkm"><noscript id="2awkm"></noscript></rt>
        <rt id="2awkm"><noscript id="2awkm"></noscript></rt>
      • <dfn id="2awkm"></dfn>
        <menu id="2awkm"><acronym id="2awkm"></acronym></menu>
        
        
        <rt id="2awkm"></rt><dfn id="2awkm"><code id="2awkm"></code></dfn>
      • <dd id="2awkm"><s id="2awkm"></s></dd>
        <tbody id="2awkm"></tbody>
      • <dfn id="2awkm"></dfn>
        <menu id="2awkm"><noscript id="2awkm"></noscript></menu>
        激情五月 开心五月 | 潘金莲裸体高潮 | 亚洲第一色在线观看 | 99视频这里有精品 | 加勒比伊人一区二区综合久久爱 |