机器视觉 throw算子

Posted 沧海一笑-dj

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了机器视觉 throw算子相关的知识,希望对你有一定的参考价值。

00. 目录

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])
  endtry

07. 附录

7.1 机器视觉博客汇总
网址:https://dengjin.blog.csdn.net/article/details/116837497

以上是关于机器视觉 throw算子的主要内容,如果未能解决你的问题,请参考以下文章

机器视觉 边缘检测算子

机器视觉 exit算子

机器视觉 switch算子

机器视觉 export_def算子

机器视觉 insert算子(已废弃)

机器视觉 stop算子