Sap Abap Try Catch ile hata yakalamak, nasıl hata yakalanır dump önlemek ? CX_AI_SYSTEM_FAULT in RFC hatasını yakalamak ?

Paylaş.

  Basit kullanımı ile try ile hata yakalamak aşağıdaki gibidir.

ty ile yakalayıp catch ile içeriği yazdırabilirsiniz.

  

TRY.
    CALL METHOD o1->m1.
    PERFORM f1.
  CATCH cx_root.  “Handler for all exceptions
       ” ABAP code(What to do when error occures)……..
ENDTRY.

FORM f1 RAISING cx_my.
  TRY.
    IF …… RAISE EXCEPTION TYPE cx_my2. ENDIF.
      CALL METHOD o1->m3.
  CATCH cx_my1 cx_my3 INTO ex.
    RAISE EXCEPTION TYPE cx_my4.
  CATCH cx_my4.
     “Handler for exceptions of type cx_my4
     ” ABAP code(What to do when error occures)……..
  CLEANUP.
     “Cleanup section, used to restore to a consistant state
     ” ABAP code……..
  ENDTRY.
ENDFORM.


“&——————————————————–

“&

“&——————————————————–

  REPORT  TRYORNEGI.

parameters NUMBER type I.

data RESULT type P decimals 2.
data OREF type ref to CX_ROOT.
data TEXT type STRING.

start-of-selection.

  write: / ‘Testing division and Sqare root with’, NUMBER.
  uline.

    try.
    if ABS( NUMBER ) > 100.
      raise exception type CX_DEMO_ABS_TOO_LARGE.
  endif.
    try.
      RESULT =  1 / NUMBER.
      write: / ‘Result of division:’, RESULT.
      RESULT = SQRT( NUMBER ).
      write: / ‘Result of square root:’, RESULT.
      catch CX_SY_ZERODIVIDE into OREF.
      TEXT = OREF->GET_TEXT( ).
      cleanup.
        clear RESULT.
  endtry.
    catch CX_SY_ARITHMETIC_ERROR into OREF.
      TEXT = OREF->GET_TEXT( ).
    catch CX_ROOT into OREF.
      TEXT = OREF->GET_TEXT( ).
  endtry.
  if not TEXT is initial.
    write / TEXT.
  endif.
  write: / ‘Final result:’, RESULT.

 “&————————————————————–

“&  CX_AI_SYSTEM_FAULT ile hata yakalamak

 “&————————————————————–

http://wiki.sdn.sap.com/wiki/display/Snippets/How+to+handle+CX_AI_SYSTEM_FAULT+in+RFC

https://www.sdn.sap.com/irj/scn/thread?threadID=1070418&tstart=120

Description

Courtesy of OLE from the above thread. This is very useful when calling a Client Proxy. The SAP help isn’t very clear on how to handle system exceptions in an RFC. I was getting the warning “The exception CX_AI_SYSTEM_FAULT is neither caught nor is declared in the RASING clause of <function>” when I checked the function in SE37.

data: lo_system_ex type ref to cx_ai_system_fault,
lo_app_ex type ref to cx_ai_application_fault,
l_sys_exc TYPE REF TO cx_ai_system_fault,
l_app_exc TYPE REF TO cx_ai_application_fault,
l_exception_msg type string.
 
 
try.
create object l_wsproxy.
 
try.
call method l_wsproxy->execute_synchronous
exporting
output = ****
importing
input = ****.
catch cx_ai_system_fault into l_sys_exc.
catch cx_ai_application_fault into l_app_exc.
endtry.
 
catch cx_ai_system_fault into l_sys_exc.
endtry.
l_exception_msg = l_sys_exc->get_text( ).
write l_exception_msg.

VN:F [1.9.22_1171]
Rating: 6.0/10 (1 vote cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
Sap Abap Try Catch ile hata yakalamak, nasıl hata yakalanır dump önlemek ? CX_AI_SYSTEM_FAULT in RFC hatasını yakalamak ?, 6.0 out of 10 based on 1 rating