Home

DBMS_UTILITY.FORMAT_ERROR_STACK and FORMAT_ERROR_BACKTRACE should be used together

Rule description

  • DBMS_UTILITY.FORMAT_ERROR_STACK and FORMAT_ERROR_BACKTRACE should be used together

 

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 DBMS_UTILITY.FORMAT_ERROR_STACK  is used)
    Log_Errors ( 'Error Log...' || Chr(10) ||
		DBMS_UTILITY.FORMAT_ERROR_STACK() );
    DBMS_OUTPUT.PUT_LINE ( '----------' );
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 (FORMAT_ERROR_STACK and FORMAT_ERROR_BACKTRACE are used together)
    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 ( '----------' );
END CUSTOMER_TABLE_ITERATION;
Visual Expert 2020
 VEPLSQLRULE130