Halcon異常(C++)不起作用


現象

 

Halcon導出的C++程序,try catch不到異常。在Halcon下可以正常Catch到異常。 
C++代碼:
try
{
   tuple_max(hv_Length, &hv_Max);//這里有問題,會出異常,但是,C++中捕捉不到該異常??
}
catch(HalconCpp::HException &HDevExpDefaultException)
{
   HDevExpDefaultException.ToHTuple(&hv_Exception);
  hv_ErrorCode = ((const HTuple&)hv_Exception)[0];
}
異常:

 
 原因 
 Halcon的異常(HDevExpDefaultException)沒有被“安裝”。
Halcon中提供了安裝方法,static Handler InstallHHandler(Handler proc)。
可以定義自己程序的異常,在try catch前使用InstallHHandler安裝。
修改方法:
1,自定義異常:
void MyHalconExceptionHandler(const HException& except)
{
throw except;
},
2,在構造函數中,進行安裝:
HException::InstallHHandler(&MyHalconExceptionHandler);

3,調用try catch塊
try
{
   tuple_max(hv_Length, &hv_Max);
}
catch(HalconCpp::HException &except) 
{
   //do something
}

參考:
1,HALCON / C++ User’s Manual 第五章Chapter 5 Exception Handling
2,Halcon幫助文檔, Programmer's Gude - 11.3 Error Handling
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM