2023-05-03 11:06:20 +02:00
|
|
|
== Why is this an issue?
|
|
|
|
|
2021-04-28 16:49:39 +02:00
|
|
|
Centralizing the definitions of custom exceptions comes with two major benefits:
|
|
|
|
|
|
|
|
* The duplication of the exceptions declarations and ``++PRAGMA EXCEPTION_INIT++`` is avoided
|
|
|
|
* The risk of associating multiple different exceptions to the same number is reduced
|
|
|
|
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Noncompliant code example
|
2021-04-28 16:49:39 +02:00
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,sql]
|
2021-04-28 16:49:39 +02:00
|
|
|
----
|
|
|
|
SET SERVEROUTPUT ON
|
|
|
|
|
|
|
|
DECLARE
|
|
|
|
user_not_found EXCEPTION;
|
|
|
|
PRAGMA EXCEPTION_INIT(user_not_found, -20000); -- Noncompliant, user_not_found is bound to -20000
|
|
|
|
BEGIN
|
|
|
|
NULL;
|
|
|
|
END;
|
|
|
|
/
|
|
|
|
|
|
|
|
DECLARE
|
|
|
|
user_not_found EXCEPTION;
|
|
|
|
PRAGMA EXCEPTION_INIT(user_not_found, -20000); -- Noncompliant, user_not_found is again bound to -20000, duplication
|
|
|
|
BEGIN
|
|
|
|
NULL;
|
|
|
|
END;
|
|
|
|
/
|
|
|
|
|
|
|
|
DECLARE
|
|
|
|
wrong_password EXCEPTION;
|
|
|
|
PRAGMA EXCEPTION_INIT(wrong_password, -20000); -- Noncompliant, wrong_password is bound to -20000, conflicting with user_not_found
|
|
|
|
BEGIN
|
|
|
|
NULL;
|
|
|
|
END;
|
|
|
|
/
|
|
|
|
----
|
|
|
|
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Compliant solution
|
2021-04-28 16:49:39 +02:00
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,sql]
|
2021-04-28 16:49:39 +02:00
|
|
|
----
|
|
|
|
SET SERVEROUTPUT ON
|
|
|
|
|
|
|
|
CREATE PACKAGE exceptions AS
|
|
|
|
user_not_found EXCEPTION;
|
|
|
|
wrong_password EXCEPTION;
|
|
|
|
|
|
|
|
PRAGMA EXCEPTION_INIT(user_not_found, -20000); -- Non-Compliant (flag as false-positive)
|
|
|
|
PRAGMA EXCEPTION_INIT(wrong_password, -20001); -- Non-Compliant (flag as false-positive), conflicts are easier to avoid
|
|
|
|
END;
|
|
|
|
/
|
|
|
|
|
|
|
|
DROP PACKAGE exceptions;
|
|
|
|
----
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2021-09-20 15:38:42 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::message.adoc[]
|
|
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|