ARTICLE
Exceptions, TRY
This example demonstrates the TRY control structure.
ABAP_SOURCE_CODE
ABAP_EXEC
ABAP_DESCRIPTION
If the content of number is larger than 100, in the TRY
block the TRY control structure of the
framework program will trigger an
exception of the class CX_DEMO_ABS_TOO_LARGE . This exception is
handled by the second CATCH block of the same TRY control
structure since the subclass of the most general exception is
CX_ROOT .
If the content of number is 0, the runtime environment in the
TRY block of the TRY control structure of the called
method calculation triggers an exception of the predfined class
CX_SY_ZERODIVIDE . This is handled in the CATCH block of
the same TRY control structure.
If the content of number is a negative number, the runtime
environment in the TRY block of the TRY control structure
of the called method calculation triggers an exception of the
predefined class CX_SY_ARG_OUT_OF_DOMAIN . Since in this TRY
control structure there is no handler defined for this exception,
the exception is propagated from the method - which is possible through
the declaration of the superclass CX_SY_ARITHMETIC_ERROR with
RAISING in the method interface. Beforehand, the CLEANUP
block of the inner TRY control structure is executed.
Other possible exceptions are handled in the last CATCH block of
the TRY control structure of the framework program. This block
catches all possible exceptions through the specification of the most
general exception class CX_ROOT . If, for example,
CX_SY_ARG_OUT_OF_DOMAIN or one of its superclasses is not declared in
the method interface, you would have the exception
CX_SY_NO_HANDLER
, which would be handled in the last CATCH block.
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved