Home

Overridden Predefined Exceptions

Description

    The "Overridden Predefined Exceptions" rule in PL/SQL code states that when a predefined exception is raised, the associated error code and error message should be overridden with a user-defined error code and message. This allows for more precise control over the error handling process, as well as providing more meaningful error messages to the user. This rule also states that the user-defined error code should be unique, and should be used consistently throughout the code. Additionally, the user-defined error message should provide more information about the cause of the error, and should be written in a language that is easily understood by the user.

Key Benefits

  • Customization: Overridden predefined exceptions allow developers to customize the exception handling process and create more meaningful error messages.
  • Reusability: Overridden predefined exceptions can be reused in multiple applications, making the development process more efficient.
  • Scalability: Overridden predefined exceptions are easily scalable and can be used in different contexts and environments.
  • Debugging: Overridden predefined exceptions provide more detailed information about errors, making debugging easier.

 

Non-compliant Code Example

DECLARE
NO_DATA_FOUND EXCEPTION;        --Non compliant code (Predefined exceptions is override)

BEGIN
	FOR i IN 1 .. CUSTOMER_TABLE.COUNT
		LOOP
			IF CUSTOMER_TABLE(i) IS NOT NULL THEN
				DBMS_OUTPUT.PUT( i || ' = (' || CUSTOMER_TABLE(i).Name || ', ' || CUSTOMER_TABLE(i).PhoneNumber || ')' );
			END IF;
		END LOOP;
EXCEPTION
  WHEN NO_DATA_FOUND THEN
	Log_Errors ( 'No data found');
  WHEN ERRORS THEN
	Log_Errors ( 'Error Log...' || Chr(10) ||
		DBMS_UTILITY.FORMAT_ERROR_STACK() );
    Log_Errors ( 'Error Log...' || Chr(10) ||
		DBMS_UTILITY.FORMAT_ERROR_BACKTRACE() );
    DBMS_OUTPUT.PUT_LINE ( '----------' );
    RAISE;
END CUSTOMER_TABLE_ITERATION;

Compliant Code Example

DECLARE
VE_NO_DATA_FOUND EXCEPTION;        --Compliant code

BEGIN
	FOR i IN 1 .. CUSTOMER_TABLE.COUNT
		LOOP
			IF CUSTOMER_TABLE(i) IS NOT NULL THEN
				DBMS_OUTPUT.PUT( i || ' = (' || CUSTOMER_TABLE(i).Name || ', ' || CUSTOMER_TABLE(i).PhoneNumber || ')' );
			END IF;
		END LOOP;
EXCEPTION
  WHEN NO_DATA_FOUND THEN
	Log_Errors ( 'No data found');
  WHEN VE_NO_DATA_FOUND THEN
	Log_Errors ( 'Error Log...' || Chr(10) ||
		DBMS_UTILITY.FORMAT_ERROR_STACK() );
    Log_Errors ( 'Error Log...' || Chr(10) ||
		DBMS_UTILITY.FORMAT_ERROR_BACKTRACE() );
    DBMS_OUTPUT.PUT_LINE ( '----------' );
    RAISE;
END CUSTOMER_TABLE_ITERATION;
Visual Expert 2024
 VEPLSQLRULE6