gpt4 book ai didi

exception - 如何捕获运行时错误 DATREF_NOT_ASSIGNED?

转载 作者:行者123 更新时间:2023-12-02 19:07:02 27 4
gpt4 key购买 nike

ABAP 中是否可以使用 TRY-CATCH 子句捕获 DATREF_NOT_ASSIGNED?

DATREF_NOT_ASSIGNED 属于 ABAP 编程错误类别,这意味着:“ABAP 程序中的错误,例如被零除或未捕获的可捕获异常。”

问题:修改以下代码以捕获 DATREF_NOT_ASSIGNED:

data gv_i type ref to i.
gv_i->*17.

这个错误的简单处理是:

data gv_i type ref to i.
if gv_i is initial.
gv_i = new #( ).
endif.
gv_i->*17.

所需的解决方案将使用 TRY-CATCH 或其他构造来处理异常/错误。下面的代码不起作用:

data gv_i type ref to i.
try.
gv_i->* = 17.
catch CX_ROOT.
gv_i = new #( ).
endtry.

最佳答案

您无法捕获 DATREF_NOT_ASSIGNED。

ABAP language documentation for the Dereferencing Operator ->*证实了这一点:

If the data reference variable contains the null reference, the non-handleable exception DATREF_NOT_ASSIGNED is raised when the dereferencing operator is used.

使用is not bond检查空引用:

data gv_i type ref to i.
if gv_i is not bound.
gv_i = new #( ).
endif.
gv_i->*17.

关于exception - 如何捕获运行时错误 DATREF_NOT_ASSIGNED?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64894905/

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