gpt4 book ai didi

progress-4gl - try catch 进行中

转载 作者:行者123 更新时间:2023-12-04 04:09:56 25 4
gpt4 key购买 nike

有没有类似于php中的try catch的方法?

try {
...
}
catch (Exception $e) {
...
}

我已经使用了这种类型的块: DO ON ERROR UNDO ...但我想知道是否有另一种方法可以做到。

谢谢。

最佳答案

是的。从 11.2 版开始,就有 BLOCK-LEVEL ON ERROR UNDO, THROW.更改整个程序的默认行为的语句。 CATCH已经存在了更长的时间 - 从 10.1C 版开始。

/* Must be first line of program */
BLOCK-LEVEL ON ERROR UNDO, THROW.

DEFINE VARIABLE i AS INTEGER NO-UNDO.

i = INTEGER("Hello").

CATCH err AS Progress.Lang.Error:
MESSAGE "Error: " err:GetMessage(1)
VIEW-AS ALERT-BOX ERROR.
END.
老式程序,如您的示例,取自 Progress KnowledgeBase .
DO ON ERROR UNDO, THROW:
/* The following line raises error (138) which is diverted to a Progress.Lang.SysError object and thrown to the main block. */
FIND Customer 1000.
END.

CATCH eAnyError AS Progress.Lang.Error:
MESSAGE
"Error Number:~t" eAnyError:GetMessageNum(1) "~n"
"Error Text:~t" eAnyError:GetMessage(1)
VIEW-AS ALERT-BOX BUTTONS OK TITLE "Error processing in the CATCH for mainprocedure block".
END CATCH.
错误撤销、抛出的块级完整描述
从手册:

Syntax BLOCK-LEVEL ON ERROR UNDO, THROW.

This statement affects the following block types:

Main block of an external procedure (.p)

Internal procedures

User-defined functions

Methods of a class

Class constructors

Property accessors

ON blocks used as database triggers with CREATE, DELETE, WRITE orASSIGN events

REPEAT blocks

FOR blocks

DO TRANSACTION blocks

This statement does not affect:
Destructors

Error directives that are explicitly coded in individual, non routine-level blocks

ON blocks that are UI triggers.

Note these alternatives to the BLOCK-LEVEL ON ERROR UNDO, THROWstatement:
Instead of adding the statement to source-code files, youcan use the -undothrow 2 startup parameter to change the defaulterror-handling to UNDO, THROW on every block affected by theBLOCK-LEVEL statement during compilation. See the Startup Command andParameter Reference for more information.

The ROUTINE-LEVEL ON ERROR UNDO, THROW statement can be used if youwant to change the default error-handling only on routine-levelblocks. (You can use the -undothrow 1 startup parameter to change thedefault error-handling on routine-level blocks to UNDO, THROW duringcompilation.)

关于progress-4gl - try catch 进行中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23127756/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com