【机器视觉】 HDevelop语言基础(六)-错误处理
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 異常處理的應用方式如下:
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 exception05. HDevelop 元組操作總結
06. 附錄
6.1 機器視覺博客匯總
網址:https://dengjin.blog.csdn.net/article/details/116837497
總結
以上是生活随笔為你收集整理的【机器视觉】 HDevelop语言基础(六)-错误处理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【机器视觉】 HDevelop语言基础(
- 下一篇: 【机器视觉】dev_update_on和