日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

【机器视觉】 try算子

發(fā)布時(shí)間:2024/4/24 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【机器视觉】 try算子 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

00. 目錄

文章目錄

    • 00. 目錄
    • 01. 概述
    • 02. 簽名
    • 03. 描述
    • 04. 注意
    • 05. 參數(shù)
    • 06. 結(jié)果
    • 07. 附錄

01. 概述

try - 開(kāi)始一個(gè)程序分段,檢測(cè)并捕獲異常。

02. 簽名

try( : : : )

03. 描述

使用算子try,catch,endtry和throw可以在HDevelop中實(shí)現(xiàn)動(dòng)態(tài)的異常處理,這相當(dāng)于C ++和C#中的異常處理。 通過(guò)算子try,catch和endtry,形成兩個(gè)代碼分段:第一個(gè)分段(try… catch)包含執(zhí)行正常程序邏輯的被監(jiān)控程序行。 第二個(gè)分段(catch … endtry)包含在發(fā)生異常時(shí)運(yùn)行的代碼。

算子try為下面的程序行啟用異常處理,即,監(jiān)控下面直到catch的代碼塊是否發(fā)生異常。 如果下面程序行的運(yùn)行過(guò)程中發(fā)生錯(cuò)誤或發(fā)生另一個(gè)異常狀態(tài),或者如果算子throw顯式拋出異常,則try分段立即跳出(或者 - 取決于用戶(hù)偏好 - 顯示一個(gè)錯(cuò)誤消息框),程序繼續(xù)在相應(yīng)的catch算子后運(yùn)行。 如果在從try分段(直接或通過(guò)其他過(guò)程調(diào)用)調(diào)用的程序中引發(fā)異常,則try分段調(diào)用堆棧上的程序調(diào)用和所有中間過(guò)程調(diào)用立即中止(或者,如果適用的話(huà),在顯示錯(cuò)誤消息框之后)。 If the exception is thrown within a procedure that was called from the try block (directly or via other procedure calls), the procedure call and all intermediate procedure calls that are on the call stack above the try block are immediatly aborted (or, if applicable, also after displaying an error message box).

在拋出異常之前是否顯示錯(cuò)誤消息框由HDevelop首選項(xiàng)“Suppress error messages (throw directly an HDevelop Exception)”控制,可通過(guò)’Edit’ - >‘Preferences’ - >‘General Options’ - >‘Experienced User’。 這個(gè)消息框還提供了在拋出異常之前停止程序運(yùn)行的時(shí)機(jī),以便編輯可能的錯(cuò)誤算子調(diào)用。

監(jiān)視異常的程序分段以相應(yīng)的catch算子結(jié)束。 如果在監(jiān)視的try分段內(nèi)沒(méi)有發(fā)生異常,則忽略下面的catch分段,并在相應(yīng)的endtry算子后繼續(xù)運(yùn)行程序。

每個(gè)try-catch-endtry分段可以互相嵌套,條件是在一個(gè)程序或不同程序調(diào)用中,任何內(nèi)部的try-catch-endtry分段位于外部被嵌套的的try-catch或者catch-endtry分段內(nèi)。 如果在一個(gè)內(nèi)部try-catch分段內(nèi)拋出一個(gè)異常,將被捕獲到它本身相應(yīng)的catch-endtry塊中進(jìn)行異常處理。 因此,除非通過(guò)從catch塊中調(diào)用throw運(yùn)算符顯式地重新拋出異常,否則對(duì)于外部try-catch塊,異常是不可見(jiàn)的。

如果在HALCON算子中發(fā)生錯(cuò)誤,則會(huì)創(chuàng)建一個(gè)異常元組并將其傳遞給負(fù)責(zé)捕獲異常的catch算子。 元組收集有關(guān)錯(cuò)誤的信息,如錯(cuò)誤代碼和錯(cuò)誤文本。 捕捉到異常后,可以通過(guò)操作符dev_get_exception_data的幫助來(lái)訪(fǎng)問(wèn)這些信息。 有關(guān)傳遞的異常數(shù)據(jù)的更多信息,如何訪(fǎng)問(wèn)它們以及有關(guān)代碼導(dǎo)出的注意事項(xiàng),請(qǐng)參閱該算子的說(shuō)明。 算子throw的說(shuō)明描述了如何拋出用戶(hù)定義的異常元組。

HDevelop提供了禁止處理HALCON錯(cuò)誤的機(jī)會(huì)。 這可以通過(guò)調(diào)用運(yùn)算子dev_set_check(’?give_error’)或取消選中對(duì)話(huà)框’Edit-> Preferences-> Runtime Settings’中的’Give Error’復(fù)選框來(lái)實(shí)現(xiàn)。 如果關(guān)閉了錯(cuò)誤處理關(guān),在發(fā)生HALCON錯(cuò)誤的情況下,不會(huì)拋出異常,但程序繼續(xù)正常運(yùn)行。 與此不同的是,算子throw將始終拋出一個(gè)異常,與“give_error”設(shè)置無(wú)關(guān)。 如果在評(píng)估參數(shù)表達(dá)式期間發(fā)生錯(cuò)誤,也是如此。

原文描述

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#. By the operators try, catch, and endtry two code blocks are formed: the first one (try … catch) contains the watched program lines that perform the normal program logic. The second block (catch … endtry) contains the code that has is executed if an exception occurs.

The operator try enables the exception handling for the following program lines, i.e., the following code block up to the corresponding catch operator is watched for exceptions. If during the execution of the subsequent program lines an error or another exceptional state occurs, or if an exception is thrown explicitly by the operator throw, the try block is left immediately (or—depending on a user preference—after displaying an error message box) and the program execution continues at the corresponding catch operator. If the exception is thrown within a procedure that was called from the try block (directly or via other procedure calls), the procedure call and all intermediate procedure calls that are on the call stack above the try block are immediately aborted (or, if applicable, also after displaying an error message box).

Whether an error message box is displayed before the exception is thrown or not, is controlled by the HDevelop preference ‘Suppress error messages (throw directly an HDevelop Exception)’ that can be reached via ‘Edit->Preferences->General Options->Experienced User’. This message box also offers the opportunity to stop the program execution before the exception is thrown in order to edit the possibly erroneous operator call.

The program block that is watched for exceptions ends with the corresponding catch operator. If within the watched try block no exception occurred, the following catch block is ignored and the program execution continues after the corresponding endtry operator.

try-catch-endtry blocks can be nested arbitrarily into each other, within a procedure or over different procedure calls, as long as any inner try-catch-endtry block lies completely either within an outer try-catch or a catch-endtry block. If an exception is thrown within an inner try-catch block, the exception handling is caught in the corresponding catch-endtry block. Hence, the exception is not visible for the outer try-catch blocks unless the exception is rethrown explicitly by calling a throw operator from the catch block.

If within a HALCON operator an error occurs, an exception tuple is created and passed to the catch operator that is responsible for catching the exception. The tuple collects information about the error such as the error code and the error text. After catching an exception, this information can be accessed with the help of the operator dev_get_exception_data. For more information about the passed exception data, how to access them, and considerations about the code export, see the description of that operator. The reference of the operator throw describes how to throw user-defined exception tuples.

HDevelop offers the opportunity to disable the handling of HALCON errors. This can be achieved by calling the operator dev_set_check(’~give_error’) or by unchecking the check box ‘Give Error’ on the dialog ‘Edit->Preferences->Runtime Settings’. If the error handling is switched off, in case of an HALCON error no exception is thrown but the program execution is continued as normal at the next operator. In contrast to that, the operator throw will always throw an exception independently of the ‘give_error’ setting. The same applies if an error occurred during the evaluation of an parameter expression.

04. 注意

算子try,catch,endtry和throw不支持C語(yǔ)言導(dǎo)出,支持語(yǔ)言C ++,C#和VisualBasic / .NET。 只有后者支持跨程序拋出異常。

05. 參數(shù)

無(wú)

06. 結(jié)果

try總是返回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

程序示例

tryread_image (Image, 'may_be_not_available') catch (Exception)if (Exception[0] == 5200)dev_get_exception_data (Exception, 'error_message', ErrMsg)set_tposition (3600, 24, 12)write_string (3600, ErrMsg)return ()else* rethrow the exceptionthrow ([Exception,'unknown exception in myproc'])endif endtry

07. 附錄

7.1 機(jī)器視覺(jué)博客匯總
網(wǎng)址:https://dengjin.blog.csdn.net/article/details/116837497

總結(jié)

以上是生活随笔為你收集整理的【机器视觉】 try算子的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。