【机器视觉】 throw算子
00. 目錄
文章目錄
- 00. 目錄
- 01. 概述
- 02. 簽名
- 03. 描述
- 04. 注意
- 05. 參數
- 06. 結果
- 07. 附錄
01. 概述
throw- 拋出一個用戶定義的異常或重新拋出一個捕獲的異常。
02. 簽名
throw( : : Exception : )
03. 描述
? 使用try,catch,endtry和throw等算子可以在HDevelop中實現動態的異常處理,這相當于(comparable)與C ++和C#中的異常處理。 HDevelop中異常處理的基本思想也在算子try,dev_set_check以及“HDevelop User’s Guide”中進行了描述。
算子throw提供了一個可以從程序中的任意位置拋出異常的時機。 這個異常可以被周圍的try-catch塊的catch算子捕獲。 通過這種方式,開發者能夠定義他自己的特定的錯誤或異常狀態,為了繼續特定的交叉程序(cross-procedure)異常處理,例如為了釋放資源或從定義的狀態重新開始,正常的程序執行被中止。(By this means the developer is able to define his own specific error or exception states, for which the normal program execution is aborted in order to continue with a specific cross-procedure exception handling, e.g., for freeing ressources or restarting from a defined state.)
在這樣的用戶定義的異常中,可以拋出幾乎任意的元組作為Exception參數,元組的第一個元素應該被設置為用戶定義的錯誤代碼> = 30000。
另外,使用此算子可以重新拋出算子catch捕獲的異常。 例如,如果在一個內部的try-catch-endtry塊內(例如,在一個外部程序中),只有特定的異常可以以適當的方式處理,而所有其他異常必須傳遞給調用者, 被一個外部的 try-catch-endtry塊捕獲和處理。
為了重新拋出一個被捕獲的異常,可以將由catch算子捕獲的Exception元組直接傳遞給throw算子的Exception參數。 此外,可以在異常元組中追加任意的(但不能是圖形)用戶數據,可以通過算子dev_get_exception_data將異常捕獲為“user_data”后訪問:
try...catch (Exception)...UserData := ...throw ([Exception, UserData])endtry原文描述:
With the help of the operators try, catch, endtry, and throw it is possible to implement a dynamic exception handling in HDevelop, which is comparable to the exception handling in C++ and C#. The basic concepts of the exception handling in HDevelop are also described at the operators try, and dev_set_check as well as in the “HDevelop User’s Guide”.
The operator throw provides an opportunity to throw an exception from an arbitrary place in the program. This exception can be caught by the catch operator of a surrounding try-catch block. By this means the developer is able to define his own specific error or exception states, for which the normal program execution is aborted in order to continue with a specific cross-procedure exception handling, e.g., for freeing resources or restarting from a defined state.
In such a user-defined exception a nearly arbitrary tuple can be thrown as the Exception parameter, merely the first element of the tuple should be set to a user-defined error code >= 30000.
In addition, with the help of the operator throw it is possible to rethrow an exception that was caught with the operator catch. This may be sensible, for instance, if within an inner try-catch-endtry block (e.g., within an external procedure) only specific exceptions can be handled in an adequate way and all other exceptions must be passed to the caller, where they can be caught and handled by an outer try-catch-endtry block.
For rethrowing a caught exception, it is possible to pass the Exception tuple that was caught by the catch operator directly to the Exception parameter of the throw operator. Furthermore, it is possible to append arbitrary (but no iconic) user data to the Exception tuple, that can be accessed after catching the exception as ‘user_data’ with the operator dev_get_exception_data:
04. 注意
算子導出try,catch,endtry和throw不支持C語言,支持語言C ++,C#和VisualBasic / .NET。 只有后者支持跨程序拋出異常。
05. 參數
Exception (input_control) exception-array → (integer / string)
返回異常數據或用戶定義的錯誤代碼的元組。
06. 結果
如果指定參數的值是正確的,則throw(作為算子)返回2(H_MSG_TRUE)。 否則會引發異常并返回錯誤代碼。
HDevelop例程
try_catch.hdev Demonstrate the usage of the exception handling in HDevelop
set_shape_model_timeout.hdev Demonstrate how to use the timeout mechanism for shape-based matching
cancel_draw_result.hdev Enable user-defined actions when a draw operation is canceled
程序示例
try...catch (Exception)...UserData := ...throw ([Exception, UserData])endtry07. 附錄
7.1 機器視覺博客匯總
網址:https://dengjin.blog.csdn.net/article/details/116837497
總結
以上是生活随笔為你收集整理的【机器视觉】 throw算子的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【机器视觉】 stop算子
- 下一篇: 【机器视觉】 break算子