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

Throw statement equivalent in ABAP Objects

Former Member
0 Likes
1,713

Hi All,

I am trying to raise an exception and use a throw statement after catch inside try endtry in ABAP objects. Later i understood that there is no throw statement defined in ABAP objects. Could anyone help me out to understand the equivalent throw statement in ABAP and how to use in raise exception. I am pasting my code below for reference.

try.

-


---

CATCH Zxx_EXCEPTION into err.

write:/ err->local_text.

  • message err->LOCAL_TEXT type 'I'.

if err->local_text = ZIF_XXXX~BUSOBJLOCKED.

throw CX_AI_APPLICATION_FAULT.

endtry.

Thanks

Deno

6 REPLIES 6
Read only

RichHeilman
Developer Advocate
Developer Advocate
Read only

uwe_schieferstein
Active Contributor
0 Likes
1,110

Hello Deno

The TRY/CATCH logic of ABAP-OO is pretty much the same like in Java. Instead of throwing exception we have to raise them.

Method execute somewhere raise an exception of class zcx_myexception.

method execute.

  if ( condition = abap_true ).
 ... 
  else.
    RAISE EXCEPTION TYPE zcx_myexception
      EXPORTING
        textid = ...
        <parameter> = ...
  endif.
  
endmethod.

TRY.
  call method go->execute( ).

  CATCH zcx_myexception INTO lo_error.
* Do error handling
ENDTRY.

If the method that calls go->execute does not surround the method call by TRY/CATCH then it must define the exception class in its interface and, thereby, propagate the exception to the next higher level calling method.

Regards

Uwe

Read only

0 Likes
1,110

Just on slight addition to Uwe how to propagte Instances of exception classes in the signature of methods depends wether they inherit from

CX_NO_CHECK

CX_DYNAMIC_CHECK

CX_STATIC_CHECK

you will find some documentation attached to these classes.

Best Regards

Klaus

Read only

0 Likes
1,110

Hello Klaus

I appreciate very much your refinements and corrections because they help me to proceed from the (still) beginner level to the advanced ABAP-OO developer.

Best Regards (from Zürich)

Uwe

Read only

0 Likes
1,110

Who not? Thanks for your comments.

Hasta Luego

Klaus

Read only

0 Likes
1,110

Hi,

Thanks for all ur replies. In my scenario, once i get an exception Business object locked, I have to throw the CX_AI_Application_fault message again to send the process to queue. So that there is no manual intervention required to restart. Once the business object lock problem gets over, automatically the queue opens and message flow resumes without any manual intervention. So please let me know how this can be achieved here.

Thanks

Deno