High-level programming languages can handle all kinds of error situations and recover as far as possible. OceanBase Database allows you to handle PL Compile-Time alerts and runtime exceptions.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only the MySQL mode.
A PL block in OceanBase Database provides the EXCEPTION and EXCEPTION HANDLER keywords to handle errors.
EXCEPTION is used to handle unexpected events that occur during normal execution, including predefined errors and custom errors. If the PL block generates an exception and does not indicate how to handle it, the program is automatically terminated.
EXCEPTION HANDLER statements are usually located in the second half of the PL program body. The syntax is as follows:
EXCEPTION
WHEN first_exception THEN <code to handle first exception >
WHEN second_exception THEN <code to handle second exception >
WHEN OTHERS THEN <code to handle others exception >
END;
Notice
Exception handlers can be sorted in any order. However, OTHERS must be located at the last position.