Home
RAISE_APPLICATION_ERROR should only be used with error codes from -20,000 to - 20,999
Description
The RAISE_APPLICATION_ERROR code rule states that the RAISE_APPLICATION_ERROR command should only be used with error codes that range from -20,000 to -20,999. This command is used to raise an exception and return an error message to the user. The error message should be meaningful and provide information about the cause of the error. This code rule ensures that the error codes used are specific and meaningful, so that the user can easily understand the cause of the error.
Key Benefits
- Error Codes: RAISE_APPLICATION_ERROR should only be used with error codes from -20,000 to - 20,999, as these are reserved for user-defined exceptions. This helps to differentiate between system-defined exceptions and user-defined exceptions.
Non-compliant Code Example
CREATE OR REPLACE PROCEDURE CheckCustomerCreditLimit (credit_limit IN number := 0,
output_result OUT number)
AS
BEGIN
IF credit_limit < 1800 then
raise_application_error(-10150,'Customer credit limit is too less !'); --Non compliant code (RAISE_APPLICATION_ERROR used error codes beyond defined range -20,000 to - 20,999)
END IF;
output_result := credit_limit;
END;
Compliant Code Example
CREATE OR REPLACE PROCEDURE CheckCustomerCreditLimit (credit_limit IN number := 0,
output_result OUT number)
AS
BEGIN
IF credit_limit < 1800 then
raise_application_error(-20150,'Customer credit limit is too less !'); --Compliant code
END IF;
output_result := credit_limit;
END;