rspec/rules/S2531/plsql/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

61 lines
1.2 KiB
Plaintext

== Why is this an issue?
Naming custom exceptions the same as predefined ones, while technically acceptable, is not a good practice.
=== Noncompliant code example
[source,sql]
----
SET SERVEROUTPUT ON
DECLARE
no_data_found EXCEPTION; -- Noncompliant, overrides an Oracle predefined exception
d VARCHAR2(1);
BEGIN
SELECT dummy INTO d FROM DUAL WHERE dummy = 'Y'; -- Will raise STANDARD.NO_DATA_FOUND
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No data found!'); -- Won't be executed, as NO_DATA_FOUND was overriden, confusing!
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Unknown error!'); -- *Will* be executed
END;
/
----
=== Compliant solution
[source,sql]
----
SET SERVEROUTPUT ON
DECLARE
my_own_exception EXCEPTION; -- Compliant
d VARCHAR2(1);
BEGIN
SELECT dummy INTO d FROM DUAL WHERE dummy = 'Y';
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No data found!'); -- *Will* be executed
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Unknown error!');
END;
/
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Rename this exception to not override a predefined exception type.
endif::env-github,rspecator-view[]