Home
Exceptions should follow a naming convention
Description
The rule "Exceptions should follow a naming convention" states that all exceptions should be named in a consistent and logical manner. This helps to make the code easier to read and understand, and helps to prevent errors due to inconsistent naming. A naming convention should be established for exceptions, and all exceptions should follow this convention. This will help to ensure that all exceptions are named in a consistent and logical manner, and that they are easy to understand and debug.
Key Benefits
- Identifiable and Distinguishable: It ensure that they are easily identifiable and distinguishable from other types of errors.
- Readability: Following a naming convention rule for exceptions makes code more readable, as it is easier to identify and understand the purpose of each exception.
- Debugging: Exceptions that follow a naming convention rule are easier to debug, as the code is more organized and easier to read.
- Maintenance: Following a naming convention rule for exceptions makes code easier to maintain, as it is easier to identify and modify the code when needed.
Non-compliant Code Example
DECLARE errorLog_ EXCEPTION; --Non compliant code (Exception is not following naming convention)
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
RETURN;
END CUSTOMER_TABLE_ITERATION;
Compliant Code Example
DECLARE errorLog EXCEPTION; --Compliant code (Exception is following naming convention)
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
RETURN;
END CUSTOMER_TABLE_ITERATION;