Home

EXCEPTION WHEN ... THEN clauses should do more than

Rule description

  • EXCEPTION WHEN ... THEN clauses should do more than RAISE

 

Non-compliant Code Example

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 ERRORS THEN      --Non compliant code (Only RAISE when exception occur)
	RAISE;         
END CUSTOMER_TABLE_ITERATION;

Compliant Code Example

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 ERRORS THEN      --Compliant code (Logging error and then raising error)
	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 2020
 VEPLSQLRULE111