Professional Documents
Culture Documents
Objectives
Overview
What is wrong with Classical exception handling
Treatable Exceptions in Release 6.10 and later
Benefits of class based exceptions
Class-Based Exceptions
Exception Classes
Triggering Class-Based Exceptions
Handling Class-Based Exceptions
Creating a global exception class
When the ABAP program or the Run time environment detects an exception
situation,an exception is triggered.
There is already a way to handle exceptions in ABAP via the RAISE statement
and the EXCEPTIONS clause in function modules and methods.
So, Why is there a need for a new exception concept?
This slide is meant to get the class thinking about the current way in which
exceptions are handled. The following example can be used to refresh the
memory on current exception handling.
All exceptions must be handled immediately after the function call, which is
cumbersome.
There is no way to group similar exceptions, except through the use of others.
Exceptions returned from classical exceptions are merely return codes and affect
no flow control processing
Class based exceptions are available. They are instances of exception classes,
which are either predefined globally in the system or user defined globally or
locally.
All known class based exceptions can be triggered with RAISE EXCEPTION and
handled with TRY control structures.
If no handler is found, a runtime error will occur
SAP provides numerous classes designated as exception classes which can be
used in ABAP objects, such as programs, function modules, classes, etc.
If an exception does not exist to handle a particular situation, it can be created,
using transaction SE24 (Class Builder).
An exception can be automatically triggered by the system, for example, an
arithmetic overflow or it can be triggered manually using the RAISE EXCEPTION
command.
Exception Classes
CX_DYNAMIC_CHECK
Exceptions defined through One of the sub classes of CX_DYNAMIC_CHECK have to be either
handled within a procedure or passed on explicitly with the addition RAISING.
This is not verified by syntax check and the check is postponed until an exception occurs.
CX_NO_CHECK
Exceptions defined through One of the sub classes of CX_NO_CHECK can be either handled
within a procedure or passed on implicitly.
We should not use Class CX_NO_CHECK or its subclasses explicitly in the RAISING addition, as
they are already contained implicitly.
Common Super Class is CX_ROOT
NOTE: The old and new ways of handling exceptions cant be mixed in
routines!
TRY
try block - Normal executable code is executed up to the CATCH. If no exceptions occurred,
processing continues after ENDTRY. If an exception occurs which is handled by the
CATCH, control passes to the CATCH block
CATCH cx_class INTO oref
CATCH block is an exception handler. cx_class is the class-based exception being handled
by the CATCH block. Exception classes should be listed starting with the most specific to
the most general
INTO oref captures the reference to the exception object. Oref must be an object reference
variable with suitable static type. Oref can be used to access the attributes and methods of
the exception object
CLEANUP
Clean up block is executed whenever an exception occurs within the TRY block and is not
handled by a CATCH within the same TRY block, BUT is handled by an surrounding TRY
block
ENDTRY
Demonstration
Demonstration
Demonstration