
Exceptions are raised when errors occur. They are raised either by the runtime environment or by the statement RAISE EXCEPTION in the program. Exceptions are represented by instances of exception classes and can either be handled in the current context or passed to a caller using the addition RAISING in the interface of procedures. Exceptions are handled in a TRY-CATCH-ENDTRY control structure. Exceptions that are not handled produce runtime errors (logged terminations of programs).
Example
Handles an arithmetic error. Division by zero raises the exception cx_sy_zerodivide, which is caught using its superclass cx_sy_arithmetic_error. The statement block statement_block is then executed.
TRY.
result = 1 / number.
CATCH cx_sy_arithmetic_error.
statement_block
ENDTRY.
Using the addition RAISING to specify exceptions makes them a part of the interface of a procedure. This makes it possible for the compiler to check at translation time whether all exceptions raised within the procedure using the statement RAISE EXCEPTION or contained in the interface of called procedures are actually handled in the procedure using CATCH or declared in the procedure interface. In certain cases, strict checks are not wanted, for example when exceptions are raised by resource bottlenecks (that cannot be handled locally) or in exceptions where the developer knows they will not be raised. For this reason, exception classes do not inherit directly from the exception root class cx_root, but one of the three derived classes cx_static_check, cx_dynamic_check, or cx_no_check. Only in the first case does the compiler make the static checks described above. In the second case, the declaration of an exception is checked at runtime, when an attempt is made to propagate the exception to the caller. If the exception is not declared in the interface, the exception cx_sy_no_handler is raised. In the latter case, no check of this type is made, either at translation time or at runtime. Exceptions can be propagated up to the level of the event blocks or dialog modules. If they are not handled here at the latest, a runtime error occurs.