zoukankan      html  css  js  c++  java
  • Halcon算子翻译——throw

    名称

    throw- 抛出一个用户定义的异常或重新抛出一个捕获的异常。

    用法

    throw( : : Exception : )

    描述

      使用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

    注意

    算子导出try,catch,endtry和throw不支持C语言,支持语言C ++,C#和VisualBasic / .NET。 只有后者支持跨程序抛出异常。

    参数

    Exception (input_control)   exception-array → (integer / string)
      返回异常数据或用户定义的错误代码的元组。

    结果

    如果指定参数的值是正确的,则throw(作为算子)返回2(H_MSG_TRUE)。 否则会引发异常并返回错误代码。

    也可以看看

    try, catch, endtry, dev_get_exception_data, dev_set_check

    模块

    Foundation

    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

  • 相关阅读:
    基于jeesit下的工作流开发步骤
    SQL Server DBA SQL
    SQL Server 全文索引的硬伤
    SQL Server全文搜索
    数据库SQL优化大总结之 百万级数据库优化方案2
    百倍性能的PL/SQL优化案例(r11笔记第13天)
    SQL优化 · 经典案例 · 索引篇
    数据库SQL优化大总结之 百万级数据库优化方案
    pytest文档23-使用多个fixture和fixture直接互相调用
    pytest文档22-fixture详细介绍-作为参数传入,error和failed区别
  • 原文地址:https://www.cnblogs.com/xhiong/p/7824841.html
Copyright © 2011-2022 走看看