A good programming language can correctly handle various error situations and recover from errors as much as possible. OceanBase Database supports handling PL compile-time warnings and exceptions (runtime errors).
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition does not support this feature.
OceanBase Database provides exception handling (EXCEPTION) and exception handlers (EXCEPTION HANDLER) in PL blocks for error handling.
An exception (EXCEPTION) is used to handle unexpected events during normal execution, including predefined errors and custom errors. If an exception is raised in a PL program block and no handling is specified, the program will automatically terminate.
The statements in the exception handler (EXCEPTION HANDLER) section are generally located in the latter part of the PL program body, and 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 arranged in any order, but the OTHERS handler must be the last one.
