Home

EXCEPTION_INIT -20,NNN calls should be centralized

Description

    The EXCEPTION_INIT -20,NNN rule states that all calls to the -20,NNN exception should be centralized in one location. This means that all code that calls the -20,NNN exception should be placed in one specific area of the code, such as a single procedure or function. This helps to ensure that all code that calls the -20,NNN exception is consistent and that any changes to the exception are made in one place. This also helps to reduce the amount of duplicate code that is written, as the same code can be used for all calls to the -20,NNN exception. By centralizing the calls to the -20,NNN exception, the code is easier to maintain and debug.

Key Benefits

  • Centralized Exception Handling: By centralizing the exception handling, it makes it easier to debug and maintain code, as well as reducing the amount of duplicate code needed.
  • Reduced Risk of Errors: By having a single point for exception handling, it reduces the risk of errors occurring due to incorrect handling of exceptions.
  • Improved Performance: By reducing the amount of duplicate code needed, it can help improve the performance of the application.

 

Non-compliant Code Example

CREATE OR REPLACE PACKAGE error_logger_pkg 
IS 
   failure_forall   EXCEPTION;
   failure_forsome   EXCEPTION;
	  
   PRAGMA EXCEPTION_INIT (failure_forsome, -22010); 
   PRAGMA EXCEPTION_INIT (failure_forall, -22010);      --Non compliant code 
END

Compliant Code Example

CREATE OR REPLACE PACKAGE error_logger_pkg 
IS 
   failure_forall   EXCEPTION;
   failure_forsome   EXCEPTION;
	  
   PRAGMA EXCEPTION_INIT (failure_forsome, -22010); 
   PRAGMA EXCEPTION_INIT (failure_forall, -22011);       --Compliant code 
END
Visual Expert 2024
 VEPLSQLRULE39