Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't catch certain exceptions

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.
like image 292
Florian Avatar asked Jun 02 '15 13:06

Florian


Video Answer


2 Answers

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:

enter image description here

or alternatively you can use the "Pattern" command in the editor to get the correct syntax.

like image 89
Esti Avatar answered Sep 20 '22 11:09

Esti


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.

like image 24
vwegert Avatar answered Sep 18 '22 11:09

vwegert