I am calling the cl_abap_typedescr=>describe_by_name
method. It could possibly throw a TYPE_NOT_FOUND
exception. I am coming form c# and in c# it would be quite easy to catch such an error. But in ABAP i am not able to catch the exception.
It starts with the fact that I can't use the TYPE_NOT_FOUND
exception object in my code. It just does not exist. It continues with the fact that catching CX_ROOT
won't help either. It just ignores my try catch clause and crashes:
TRY .
descr_ref0 ?= cl_abap_typedescr=>describe_by_name('iabc1').
CATCH cx_root.
BREAK-POINT.
ENDTRY.
I assume you need the type-casting, so have provided an additional step for it.
This syntax isn't as elegant as the new syntax, but it's the only way I could get your example to compile:
data descr_ref1 type ref to cl_abap_typedescr.
call method cl_abap_typedescr=>describe_by_name(
exporting p_name = 'abc1'
receiving p_descr_ref = descr_ref1
exceptions type_not_found = 1 ).
if sy-subrc <> 0.
break-point.
else.
descr_ref0 ?= descr_ref1.
endif.
edit:
You can tell which type of exceptions is used by looking at the method:
or alternatively you can use the "Pattern" command in the editor to get the correct syntax.
TYPE_NOT_FOUND
is not a class-based exception. You'll need to use the old syntax and assign a non-zero value to each exception, then check SY-SUBRC
whether that value reappears.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With