SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Catch System Exception



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP
View previous topic :: View next topic  
Author Message
vetal
Участник
Участник



Joined: 18 Jan 2008
Posts: 44

PostPosted: Fri Jan 18, 2008 12:22 pm    Post subject: Catch System Exception Reply with quote

Здравствуйте!
Хочу узнать о возможности перехвата системных исключений во время преобразования типов. Например:

Code:
DATA:
p1 TYPE p,
f1 TYPE f,
i1 TYPE i.

p1 = f1 / i1.


если система сгенерит какое-нибудь исключение, как перехатить его?
Back to top
View user's profile Send private message
Lord
Профессионал
Профессионал



Joined: 10 Sep 2007
Posts: 168

PostPosted: Fri Jan 18, 2008 5:45 pm    Post subject: Reply with quote

Во встроенном хелпе дано хорошее описание исключений с примерами.
Quote:
Exceptions in ABAP Statements
Error situations, that occur during the execution of an ABAP statement, lead to exceptions. These exceptions are completely integrated in the exception concept and are triggered by the runtime environment. There are:

exceptions that can be handled, which are based on predefined exception classes.
exceptions that cannot be handled, which directly lead to runtime errors.
Every exception that can be handled is assigned a runtime error, with which the program terminates if the exception is neither handled nor propagated to a caller.

For reasons of backward compatibility, exceptions that occur with many ABAP statements can be caught with TRY ... ENDTRY as well as CATCH SYSTEM-EXCEPTIONS ... ENDCATCH. For this to be the case, the runtime error assigned to the exception class must be catchable. Within a processing block, the two mechanisms exclude themselves from the handling of exceptions. We advise you, either to catch a runtime error between TRY ... ENDTRY using CATCH, or propagate it to the caller using the RAISINGaddition in the definition of the interface. From Release 6.10 onwards you should avoid catching using CATCH SYSTEM-EXCEPTIONS


Code:
DATA:
  p1 TYPE p,
  f1 TYPE f  VALUE 100.

PARAMETER: p_int TYPE i.

CATCH SYSTEM-EXCEPTIONS arithmetic_errors = 5.
  p1 = f1 / p_int.
  WRITE: / 'Result =', p1.
ENDCATCH.

SKIP.

IF sy-subrc = 5.
  WRITE / 'Division by zero!'.
ENDIF.


Code:
DATA:
  p1 TYPE p,
  f1 TYPE f  VALUE 100.

PARAMETER: p_int TYPE i.

DATA: l_oref TYPE REF TO cx_root,
      text TYPE string.

TRY.
    p1 = f1 / p_int.
    WRITE: / 'Result =', p1.
  CATCH cx_sy_zerodivide INTO l_oref.
    text = l_oref->get_text( ).
  CATCH cx_sy_arithmetic_error INTO l_oref.
    text = l_oref->get_text( ).
  CATCH cx_root INTO l_oref.
    text = l_oref->get_text( ).
  CLEANUP.
ENDTRY.

SKIP.

IF NOT text IS INITIAL.
  WRITE / text.
ENDIF.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.