8 | Error Handling with Exceptions
As you can see in Figure 8.6, class CX_ROOT also implements the IF_
SERIAL 12ABLE_08J
ECT
and 1F_MESSAGE interfaces. The I F_SERIALIZA8LE_0BJECT
interface makes it possible to serialize (or compress) an object onto a file or net-
work stream, and so on. The I F_MESSAGE interface defines methods for extracting
a short and long text description of the error message. Section 8.5.4, Defining
Exception Texts, includes more about these methods.
8.5.1 Understanding Exception Class Types
Each of the three subclass types shown in Figure 8.6 are treated differently by the
class-based exception handling framework. When building a custom exception
class, it is important to understand the differences between these base types
because it impacts how they are used in your programs. These differences are out-
lined in Table 8.1.
Exception Class Usage Type
CX_STATIC_CHECK Exceptions of this type are used to represent checked error con-
ditions that may occur within the logic of an application pro-
gram. Such exceptions must either be explicitly declared in a
procedure's interface using the RAISING addition or handled
locally within a TRY statement. If an exception of this type is not
properly handled, the compiler will issue a warning during the
syntax check.
CX_DYNAM I
C_CHECK Exceptions of this type are used to represent unchecked error
conditions that likely stem from errors in the program logic. For
example, the standard exception class CX_SY_ZERODIVIDE is
used to represent a situation where a division operation was
attempted with a divisor whose value is 0.
Realistically, this kind of error should not happen, and if it does,
it might not be possible to recover from it gracefully. Moreover,
because a mathematics-intensive program could produce this
kind of error in almost every statement, it is not practical to han-
dle all of the possible exceptions that might occur. Therefore,
exceptions of this type do not have to be explicitly handled and
are not subject to static syntax checks at compilation time. Of
course, failure to properly handle such an exception will ulti-
mately result in a runtime error.
Table 8.1 Differences Between Base-Level Exception Types
220