Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

catch class based exceptions

Former Member
0 Likes
853

hi

i am calling a outbound proxy class from a inbound proxy class. when i dragged the ourbound proxy the below code is inserted by system directly.

TRY.

CALL METHOD oref1->SEND_OUT

EXPORTING

OUTPUT = output

.

CATCH CX_AI_SYSTEM_FAULT .

ENDTRY.

i want to know the difference between writing just

CATCH CX_AI_SYSTEM_FAULT .

and

CATCH CX_AI_SYSTEM_FAULT . into objref. where objref refers to exception class CX_AI_SYSTEM_FAULT .

how does the system behave in either of the case if exception is raised.

thanks

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
0 Likes
711

When you catch into an object reference, you get an instance of the exception which has attributes that you can access. Look at the exception class in SE24, and you'll see it has: CX_AI_SYSTEM_FAULT CODECONTEXT CODE ERRORTEXT LANGUAGE as attributes.

If you don't catch into an object, then you've simply not got this information.

E.g.

DATA: lx TYPE REF TO CX_AI_SYSTEM_FAULT.
TRY.
  CALL METHOD oref1->SEND_OUT
  EXPORTING
  OUTPUT = output

  CATCH CX_AI_SYSTEM_FAULT INTO lx
    WRITE: / lx->ERRORTEXT .
ENDTRY.

matt

4 REPLIES 4
Read only

Sm1tje
Active Contributor
0 Likes
711

In both cases, no short dump is generated, because the exception is caught. However, no info about the actual error can directly be retrieved like is done in the following example.


DATA: lv_message TYPE string,
      lr_error TYPE REF TO cx_sy_zerodivide,
      y TYPE i VALUE 10,
      x TYPE i.

TRY.
    x = y / 0.

  CATCH cx_sy_zerodivide INTO lr_error.
    lv_message = lr_error->get_text( ).

ENDTRY.

But this will only be of interest, when you want to determine the error. If the catch is part of another TRY ENDTRY block, the error is navigated upwards the chain.

Hope this was somehow helpful.

Read only

matt
Active Contributor
0 Likes
712

When you catch into an object reference, you get an instance of the exception which has attributes that you can access. Look at the exception class in SE24, and you'll see it has: CX_AI_SYSTEM_FAULT CODECONTEXT CODE ERRORTEXT LANGUAGE as attributes.

If you don't catch into an object, then you've simply not got this information.

E.g.

DATA: lx TYPE REF TO CX_AI_SYSTEM_FAULT.
TRY.
  CALL METHOD oref1->SEND_OUT
  EXPORTING
  OUTPUT = output

  CATCH CX_AI_SYSTEM_FAULT INTO lx
    WRITE: / lx->ERRORTEXT .
ENDTRY.

matt

Read only

Sm1tje
Active Contributor
0 Likes
711

Matt,

I couldn't have put it any better.

Read only

matt
Active Contributor
0 Likes
711

I've been doing some PI work, so I've used this particular exception class quite a bit!

matt