00. 目录

文章目录

  • 00. 目录
  • 01. 概述
  • 02. 签名
  • 03. 描述
  • 04. 注意
  • 05. 参数
  • 06. 结果
  • 07. 附录

01. 概述

try - 开始一个程序分段,检测并捕获异常。

02. 签名

try( : : : )

03. 描述

使用算子try,catch,endtry和throw可以在HDevelop中实现动态的异常处理,这相当于C ++和C#中的异常处理。 通过算子try,catch和endtry,形成两个代码分段:第一个分段(try… catch)包含执行正常程序逻辑的被监控程序行。 第二个分段(catch … endtry)包含在发生异常时运行的代码。

算子try为下面的程序行启用异常处理,即,监控下面直到catch的代码块是否发生异常。 如果下面程序行的运行过程中发生错误或发生另一个异常状态,或者如果算子throw显式抛出异常,则try分段立即跳出(或者 - 取决于用户偏好 - 显示一个错误消息框),程序继续在相应的catch算子后运行。 如果在从try分段(直接或通过其他过程调用)调用的程序中引发异常,则try分段调用堆栈上的程序调用和所有中间过程调用立即中止(或者,如果适用的话,在显示错误消息框之后)。 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).

在抛出异常之前是否显示错误消息框由HDevelop首选项“Suppress error messages (throw directly an HDevelop Exception)”控制,可通过’Edit’ - >‘Preferences’ - >‘General Options’ - >‘Experienced User’。 这个消息框还提供了在抛出异常之前停止程序运行的时机,以便编辑可能的错误算子调用。

监视异常的程序分段以相应的catch算子结束。 如果在监视的try分段内没有发生异常,则忽略下面的catch分段,并在相应的endtry算子后继续运行程序。

每个try-catch-endtry分段可以互相嵌套,条件是在一个程序或不同程序调用中,任何内部的try-catch-endtry分段位于外部被嵌套的的try-catch或者catch-endtry分段内。 如果在一个内部try-catch分段内抛出一个异常,将被捕获到它本身相应的catch-endtry块中进行异常处理。 因此,除非通过从catch块中调用throw运算符显式地重新抛出异常,否则对于外部try-catch块,异常是不可见的。

如果在HALCON算子中发生错误,则会创建一个异常元组并将其传递给负责捕获异常的catch算子。 元组收集有关错误的信息,如错误代码和错误文本。 捕捉到异常后,可以通过操作符dev_get_exception_data的帮助来访问这些信息。 有关传递的异常数据的更多信息,如何访问它们以及有关代码导出的注意事项,请参阅该算子的说明。 算子throw的说明描述了如何抛出用户定义的异常元组。

HDevelop提供了禁止处理HALCON错误的机会。 这可以通过调用运算子dev_set_check(’〜give_error’)或取消选中对话框’Edit-> Preferences-> Runtime Settings’中的’Give Error’复选框来实现。 如果关闭了错误处理关,在发生HALCON错误的情况下,不会抛出异常,但程序继续正常运行。 与此不同的是,算子throw将始终抛出一个异常,与“give_error”设置无关。 如果在评估参数表达式期间发生错误,也是如此。

原文描述

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语言导出,支持语言C ++,C#和VisualBasic / .NET。 只有后者支持跨程序抛出异常。

05. 参数

06. 结果

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 机器视觉博客汇总
网址:https://dengjin.blog.csdn.net/article/details/116837497

【机器视觉】 try算子相关推荐

  1. 机器视觉 边缘检测算子

    1.实验目的 利用opencv python实现对下图实现边缘检测算子. 2.实验过程 (1)在python安装opencv库, pip install opencv-python. (2)在pyth ...

  2. 拉普拉斯噪声公式_高斯拉普拉斯算子(Laplace of Gaussian)

    高斯拉普拉斯(Laplace of Gaussian) Laplace算子作为一种优秀的边缘检测算子,在边缘检测中得到了广泛的应用.该方法通过对图像 求图像的二阶倒数的零交叉点来实现边缘的检测,公式表 ...

  3. python 视觉技术_python+opencv实现机器视觉基础技术(边缘提取,图像滤波,边缘检测算子,投影,车牌字符分割)...

    机器视觉是人工智能正在快速发展的一个分支.简单说来,机器视觉就是用机器代替人眼来做测量和判断.它是一项综合技术,包括图像处理.机械工程技术.控制.电光源照明.光学成像.传感器.模拟与数字视频技术.计算 ...

  4. 【机器视觉】 write_measure算子

    00. 目录 文章目录 00. 目录 01. 概述 02. 签名 03. 描述 04. 注意 05. 参数 06. 结果 07. 附录 01. 概述 write_measure - 将measure对 ...

  5. 【机器视觉】 translate_measure算子

    00. 目录 文章目录 00. 目录 01. 概述 02. 签名 03. 描述 04. 注意 05. 参数 06. 结果 07. 附录 01. 概述 translate_measure - 转换一个m ...

  6. 【机器视觉】 set_fuzzy_measure_norm_pair算子

    00. 目录 文章目录 00. 目录 01. 概述 02. 签名 03. 描述 04. 注意 05. 参数 06. 结果 07. 附录 01. 概述 set_fuzzy_measure_norm_pa ...

  7. 【机器视觉】 set_fuzzy_measure算子

    00. 目录 文章目录 00. 目录 01. 概述 02. 签名 03. 描述 04. 注意 05. 参数 06. 结果 07. 附录 01. 概述 set_fuzzy_measure - 指定一个模 ...

  8. 【机器视觉】 serialize_measure算子

    00. 目录 文章目录 00. 目录 01. 概述 02. 签名 03. 描述 04. 注意 05. 参数 06. 结果 07. 附录 01. 概述 serialize_measure - 序列化me ...

  9. 【机器视觉】 reset_fuzzy_measure算子

    00. 目录 文章目录 00. 目录 01. 概述 02. 签名 03. 描述 04. 注意 05. 参数 06. 结果 07. 附录 01. 概述 reset_fuzzy_measure - 重置一 ...

  10. 【机器视觉】 read_measure算子

    00. 目录 文章目录 00. 目录 01. 概述 02. 签名 03. 描述 04. 注意 05. 参数 06. 结果 07. 附录 01. 概述 read_measure - 从文件中读取一个me ...

最新文章

  1. JAVA     面向对象
  2. 13000行代码、19大技术,这位16岁高中生用C++从头到尾构建了一个机器学习库!...
  3. android运行exe没有反应,安卓最担心的事情发生了
  4. 最聪明女生集结清华,挑战人工智能
  5. 深入浅出gRPC——极客时间李林锋
  6. java可达性_java垃圾回收机制--可达性算法
  7. 为什么python 为什么没有接口_python没有接口吗
  8. python女朋友_教你用Python感知女朋友的情绪变化!
  9. java 连接oracle_「事件驱动架构」使用GoldenGate创建从Oracle到Kafka的CDC事件流
  10. Android 四大组件学习之BroadcastReceiver一
  11. 3x3矩阵怎么求逆矩阵_矩阵型组织结构,郭士纳与任正非都是怎么说的?
  12. 彩虹查课插件 使用说明 网课查询插件 极速版
  13. java中uri与url的区别_URL和URI的区别与总结
  14. Axure原型图(以微信作为参考)
  15. php网页怎么设置背景音乐,怎么给网页添加背景音乐
  16. 测试新人如何提高工作效率
  17. 家里安装了两条宽带,有什么方法把两家运营商的宽带聚合起来用?
  18. Deadline渲染管理系统
  19. 09组团队项目-Alpha冲刺-1/6
  20. 栈详解(顺序栈和链栈)

热门文章

  1. javascript调用Flash里对象的方法(函数)搞了五个小时。
  2. linux查看进程占用pcu,Linux运维:如何使用ss代替netstat命令
  3. java 多线程状态_总结Java中线程的状态及多线程的实现方式
  4. 常用计算机服务,常用计算机端口对应的服务(The commonly used computer port corresponding service).doc...
  5. mysql 分组查出来横向展示_Mysql探索(一):B+Tree索引
  6. html 重复提交表单,表单重复提交问题的三种解决思路
  7. oracle 触发器登录,【学习笔记】Oracle触发器 实现指定用户登录oracle案例
  8. iconpath 微信小程序_【报Bug】微信小程序 map 标记点iconPath图标 苹果手机 不能单个设置了。以前没有问题。现在不知道为啥不行了...
  9. 2013年海康威视校园招聘笔试题
  10. STL源码剖析---deque