00. 目录

文章目录

  • 00. 目录
  • 01. 概述
  • 02. 跟踪算子的返回值
  • 03. 异常处理
  • 04. HDevelop错误码
  • 05. HDevelop 元组操作总结
  • 06. 附录

01. 概述

本节介绍如何在 HDevelop 程序中处理错误。 发生错误时,默认行为HDevelop 的作用是停止程序执行并显示错误消息框。 虽然这在程序开发时肯定是有益的,但在程序实际部署时通常并不需要。 一个完成的程序应该对错误本身做出反应。 如果程序与用户交互,这尤其重要。

HDevelop 中的错误处理基本上有两种方法:
• 跟踪算子调用的返回值(错误代码)
• 使用异常处理

这些方法之间的主要区别在于应用领域:第一种方法在发生错误的过程中处理错误。 后一种方法允许错误在调用堆栈中向上工作,直到最终得到处理。

02. 跟踪算子的返回值

算子 dev_set_check 指定是否显示错误消息框。

要关闭消息框,请使用

dev_set_check('~give_error')

HDevelop 然后将忽略程序中的任何错误。 因此,程序员必须负责错误处理。 每个操作符调用都提供一个返回值(或错误代码),表示执行成功或失败。 可以通过指定的错误变量访问此错误代码:

dev_error_var(ErrorCode, 1)

此算子调用实例化变量 ErrorCode。 它存储最后执行的运算符的错误代码。 使用此错误代码,程序可以根据操作的成功来确定其进一步的流程。

...
if (ErrorCode != H_MSG_TRUE)
* react to error
endif
* continue with program
...

可以使用算子 get_error_text 获取与给定错误代码相关的错误消息。 这在向程序用户报告错误时很有用。

如果要在调用过程中处理错误,则必须在每个参与过程的接口中添加适当的输出控制变量,或者必须将错误变量定义为全局变量。

global tuple ErrorCode
dev_error_var(ErrorCode, 1)
...

03. 异常处理

HDevelop 支持动态异常处理,类似于 C++ 和 C# 中的异常处理。

监视程序行块是否存在运行时错误。 如果发生错误,则会引发异常并调用关联的异常处理程序。 异常处理程序只是另一个程序行块,除非发生错误,否则它对程序流是不可见的。 异常处理程序可以直接对错误采取行动,也可以将相关信息(即异常)传递给父异常处理程序。 这也称为重新抛出异常。

与上一节中描述的跟踪方法相反,异常处理需要将 HDevelop 设置为在出现错误时停止。 这是默认行为。 它也可以显式打开:

dev_set_check('give_error')

此外,HDevelop 可以配置为让用户选择是否抛出异常,或者自动抛出异常。 此行为在首选项选项卡 General Options -> Experienced User的用户中设置。

HDevelop 异常是包含与特定错误相关的数据的元组。 它始终包含错误代码作为第一项。 算子dev_get_exception_data 提供对异常元组元素的访问。
HDevelop 异常处理的应用方式如下:

...
try
* start block of watched program lines
...
catch(Exception)
* get error code
ErrorCode := Exception[0]
* react to error
endtry
* program continues normally
...

04. HDevelop错误码

21000 HALCON operator error
21001 User defined exception (’throw’)
21002 User defined error during execution
21003 User defined operator does not implement execution interface
21010 HALCON license error
21011 HALCON startup error
21012 HALCON operator error
21020 Format error: file is not a valid HDevelop program or procedure
21021 File is no HDevelop program or has the wrong version
21022 Protected procedure could not be decompressed
21023 Protected procedure could not be compressed and encrypted for saving
21024 Format error: file is not a valid HDevelop program
21025 Format error: file is not a valid HDevelop procedure
21026 Format error: file is not a valid HDevelop procedure library
21030 The program was modified inconsistently outside HDevelop.
21031 The program was modified outside HDevelop: inconsistent procedure lines.
21032 The program was modified outside HDevelop: unmatched control statements
21033 Renaming of procedure failed
21034 Locked procedures are not supported for the selected action.
21034 Password protection/locked procedures
21035 Parallel execution statements, iconic assignments, or iconic comparisons
21035 Procedures with advanced language elements are not supported for the selected action.
21036 Procedures with vector variables are not supported for the selected action.
21036 Vector variables
21040 Unable to open file
21041 Unable to read from file
21042 Unable to write to file
21043 Unable to rename file
21044 Unable to open file: invalid file name
21050 For this operator the parallel execution with par_start is not supported
21051 Thread creation failed
21052 Thread creation failed: exceeded maximum number of subthreads
21060 Iconic variable is not instantiated
21061 Control variable is not instantiated (no value)
21062 Wrong number of control values
21063 Wrong value type of control parameter
21064 Wrong value of control parameter
21065 Control parameter does not contain a variable
21066 Control parameter must be a constant value
21067 Wrong number of control values in condition variable
21068 Wrong type: Condition variable must be an integer or boolean
21070 Variable names must not be empty
21071 Variable names must not start with a number
21072 Invalid variable name
21073 Invalid name for a control variable: the name is already used for an iconic variable
21074 Invalid name for an iconic variable: the name is already used for a control variable
21075 An iconic variable is used in the wrong context: a control variable or a vector is expected
21076 A control variable is used in the wrong context: an iconic variable or a vector is expected
21077 An iconic vector variable is used in the wrong context: a control variable or a single value
is expected
21078 A control vector variable is used in the wrong context: an iconic variable or a single value
is expected
21080 For loop variable must be a number
21081 Step parameter of for loop must be a number
21082 End parameter of for loop must be a number
21083 Variable names must not be a reserved expression
21084 Case label value has already appeared in switch block
21085 Default label has already appeared in switch block
21086 The type of the variable could not be determined (no proper type definition found)
21087 The type of the variable could not be determined (conflicting type definitions found)
21090 A global variable with the specified name but a different type is already defined
21091 Access to an unknown global variable
21092 Access to an invalid global variable
21093 Invalid name for a global variable: the name is already used for a procedure parameter
21100 Access to an erroneous expression
21101 Wrong index in expression list
21102 Empty expression
21103 Empty expression argument
21104 Syntax error in expression
21105 Too few function arguments in expression
21106 Too many function arguments in expression
21107 The expression has no return value
21108 The expression has the wrong type
21110 The expression has the wrong type: iconic expression expected
21112 The expression has the wrong type: control expression expected
21114 The expression has the wrong vector dimension
21116 Vector expression expected
21118 Single or tuple value expression expected instead of a vector
21120 Expression expected
21121 lvalue expression expected
21122 Variable expected
21123 Unary expression expected
21124 Expression list expected
21125 Function arguments in parentheses expected
21126 One function argument in parentheses expected
21127 Two function arguments in parentheses expected
21128 Three function arguments in parentheses expected
21129 Four function arguments in parentheses expected
21130 Five function arguments in parentheses expected
21131 Right parenthesis ’)’ expected
21132 Right curly brace ’}’ expected
21133 Right square bracket ’]’ expected
21134 Unmatched right parenthesis ’)’ found
21135 Unmatched right curly brace ’}’ found
21136 Unmatched right square bracket ’]’ found
21137 Second bar ’|’ expected
21138 Function name expected before parentheses
21139 Unterminated string detected
21140 Invalid character in an expression identifier detected
21141 Parameter expression expected
21142 Parameter expression is not executable
21143 Vector method after . expected
21144 Vector method ’at’ after . expected
21145 Modifying vector methods are not allowed within parameters
21200 Syntax error in operator expression
21201 Identifier (operator or variable name) expected
21202 Syntax error in parameter list
21204 Parenthesis expected
21205 No parenthesis expected
21206 List of parameters in parenthesis expected
21207 Wrong number of parameters
21208 Unexpected characters at end of line
21209 Assign operator ’:=’ expected
21210 Expression after assign operator ’:=’ expected
21211 Expression in brackets ’[ ]’ for the assign_at index expected
21212 In for statement, after keyword ’by’ expression for parameter ’Step’ expected
21213 In for statement, after keyword ’to’ expression for parameter ’End’ expected
21214 In for statement, after assign operation (’:=’) expression for parameter ’Start’ expected
21215 In for statement, after ’for .. := .. to ..’ keyword ’by’ expected
21216 In for statement, after ’for .. := ..’ keyword ’to’ expected
21217 In for statement, assign operation ’:=’ for initializing the index variable expected
21218 After ’for’ keyword, assignment of ’Index’ parameter expected
21219 In for statement, error after ’by’ keyword in expression of parameter ’Step’
21220 In for statement, error after ’to’ keyword in expression of parameter ’End’ or the following
’by’ keyword
21221 In for statement, error after assignment operation (’:=’) in expression of parameter ’Start’
or the following ’to’ keyword
21222 In for statement, invalid variable name in parameter ’Index’ or error in the following assign-
ment operation (’:=’)
21223 for statement not complete
21224 In for statement, space after ’for’ expected
21225 In for statement, space after ’to’ expected
21226 In for statement, space after ’by’ expected
21227 Wrong type: The switch statement requires an integer value as parameter
21228 Wrong type: The case statement requires a constant integer value as parameter
21229 At the end of the case and the default statement a colon is expected
21230 Unknown operator or procedure
21231 Qualifier ’par_start’ before ’:’ or ’<ThreadID>’ expected
21232 ’<ThreadID>’ variable in angle brackets after ’par_start’ expected
21233 ThreadID variable after ’par_start<’ expected
21234 Closing angle bracket (’>’) after ’par_start<ThreadID’ expected
21235 Colon (’:’) after ’par_start<ThreadID>’ expected
21236 Operator or procedure call after ’par_start :’ expected
21900 Internal value has the wrong type
21901 Internal value is not a vector
21902 Index into internal value is out of range
21903 Internal value is not instantiated
22000 Internal operation in expression failed
22001 Internal operation in a constant expression failed
22010 Parameters are tuples with different size
22011 Division by zero
22012 String exceeds maximum length
22100 Parameter is an empty tuple
22101 Parameter has more than one single value
22102 Parameter is not a single value
22103 Parameter has the wrong number of elements
22104 Parameter contains undefined value(s)
22105 Parameter contains wrong value(s)
22106 Parameter contains value(s) with the wrong type
22200 First parameter is an empty tuple
22201 First parameter has more than one single value
22202 First parameter is not a single value
22203 First parameter has the wrong number of elements
22204 First parameter contains undefined value(s)
22205 First parameter contains wrong value(s)
22206 First parameter contains value(s) with the wrong type
22300 Second parameter is an empty tuple
22301 Second parameter has more than one single value
22302 Second parameter is not a single value
22303 Second parameter has the wrong number of elements
22304 Second parameter contains undefined value(s)
22305 Second parameter contains wrong value(s)
22306 Second parameter contains value(s) with the wrong type
22400 Calling context was not set
22401 Accessing an invalid calling context
22402 Error while accessing calling context data
22500 Communication with external application failed
22501 Debug session with external application no longer valid
22502 An unexpected error occured in the external application
22503 Wrong password to unlock procedure in external application
23100 The generic parameter value is unknown
23101 The generic parameter name is unknown
30000 User defined exception

05. HDevelop 元组操作总结




06. 附录

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

【机器视觉】 HDevelop语言基础(六)-错误处理相关推荐

  1. 【机器视觉】 HDevelop语言基础(五)-多线程

    00. 目录 文章目录 00. 目录 01. 概述 02. 启动线程 03. 等待子线程结束 04. HDevelop中线程的执行 05. 监视线程 06. 挂起和恢复线程 06. 附录 01. 概述 ...

  2. 【机器视觉】 HDevelop语言基础(一)-基本类型和常量

    00. 目录 文章目录 00. 目录 01. 概述 02. 开发环境 03. 基本类型 04. 控制类型 4.1 整型 4.2 实型 4.3 字符串 4.4 Boolean类型 4.5 句柄类型 05 ...

  3. 【机器视觉】 HDevelop语言基础(四)-流程控制语句

    00. 目录 文章目录 00. 目录 01. 概述 02. if 03. if-else 04. elseif 05. while 06. until 07. for 08. continue 09. ...

  4. 【机器视觉】 HDevelop语言基础(三)-容器和保留字

    00. 目录 文章目录 00. 目录 01. 保留字 02. 容器概述 03. 构造容器 04. 容器元素操作 05. 预留 06. 附录 01. 保留字 表 8.25 中列出的标识符是保留字,它们的 ...

  5. 【机器视觉】 HDevelop语言基础(二)-变量和表达式

    00. 目录 文章目录 00. 目录 01. 概述 02. 变量的类型 03. 变量的作用域 04. 图像对象操作 05. 输入控制参数表达式 5.1 元组操作的一般特征 5.2 赋值操作 5.3 元 ...

  6. R语言基础之第六部分 分类(史上最全含ddply、aggregate、split、by)

    R语言基础之第六部分 分类(史上最全含ddply.aggregate.split.by) 数据: 某市2014年-2018年空气质量指数日数据,需要按年分类计算每年 warm值为1和 0的均值. 数据 ...

  7. C语言基础第六课——第二节if语句(if-else格式、不带else的if结构)、借例题简述写代码流程、从键盘上输入三个整数,求出其中的最大数(打擂法、三目运算符、排序)、if语句的嵌套计算个人所得税

    C语言基础第六课--第二节 一.if语句概述 二.标准if-else格式 三.借例题简述写代码流程 四.不带else的if结构 五.例题:从键盘上输入三个整数,求出其中的最大数.(打擂法.三目运算符. ...

  8. 浅谈python语言_浅谈Python语言基础知识点!

    一.Python 语言的简述 Python语言是一种解释型.面向对象的编程语言,是一种开源语言. Python属于动态类定义语言,也是一种强调类型语言. 二.Python 语言的特点 1.简单.高级 ...

  9. JavaScript基础---语言基础(1)

    写在前面: 通过四篇博客把JS基础中的基础整理一下,方便自己查阅,这些内容对于实际项目开发中也许并不会在意,但是作为JS的语言基础,自觉还是应该熟悉.在完成这三篇博客(JavaScript基础---语 ...

最新文章

  1. JS设计模式(13)状态模式
  2. Delphi 中的颜色常量及效果图
  3. oracle 数据泵导出简单使用版
  4. struts2学习笔记--使用servletAPI实现ajax的一个小Demo
  5. python中functools_python–functools的使用 | 学步园
  6. 2019手机号码正则表达式
  7. 【JVM】JVM客户端 server模式 client 模式
  8. 就谈个py 的装饰器 decorator
  9. 【jQuery笔记Part3】02-jQuery抖动效果
  10. stl之list双向链表容器应用基础
  11. jsmind 线条_使用jsMind显示思维导图
  12. 简单了解一下电商系统中的SPU、SKU、ID,它们都是什么意思,三者又有什么区别和联系呢?
  13. 支付宝免签 个人支付宝到银行卡
  14. CR渲染器全景图如何渲染颜色通道_【3D】日不落投影灯 VR/CR投影效果制作
  15. 第十五周项目一----哈希表的运算及实现
  16. python让手机关机_Python 神操作:远程开机和关机
  17. LeetCode 1071(最大公约)
  18. double转换为二进制
  19. 10周成为数据分析师!
  20. 【开源许可协议】常见开源许可协议的核心内容(思维导图版本)

热门文章

  1. 百度网盘自动备份php,Linux定时备份数据到百度云盘
  2. c++ mysql 存储图片路径_3.用ADO实现图片在数据库中存储
  3. python中messagebox用法实例_pyqt4教程之messagebox使用示例分享
  4. c# json datatable_KoobooJson一款高性能且轻量的JSON库
  5. Java黑皮书课后题第2章:2.1(将摄氏温度转换为华氏温度)编写程序,从控制台读入double型的摄氏温度值,将其转为华氏温度,显示结果
  6. mac版smali2java_Android反编译apk并重新打包签名(Mac环境)
  7. getchar、scanf以及缓冲区的概念
  8. 在GitHub中创建目录
  9. 翻译:SQL Server中的索引内部结构:到SQL Server索引级别10的阶梯。
  10. Python学习之 !/usr/bin/python 和 !/usr/bin/env python区别