ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

【机器视觉】 throw算子

2021-06-16 14:58:10  阅读:153  来源: 互联网

标签:exception Exception try 算子 catch 视觉 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

标签:exception,Exception,try,算子,catch,视觉,throw
来源: https://blog.csdn.net/dengjin20104042056/article/details/117958105

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有