rspec/rules/S1041/plsql/rule.adoc

83 lines
1.5 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-01-27 13:42:22 +01:00
Ensure that every possible exception is caught by using a ``++WHEN OTHERS++`` clause.
2020-06-30 12:47:33 +02:00
=== Noncompliant code example
2020-06-30 12:47:33 +02:00
2022-02-04 17:28:24 +01:00
[source,sql]
2020-06-30 12:47:33 +02:00
----
SET SERVEROUTPUT ON
DECLARE
result PLS_INTEGER;
custom_exception EXCEPTION;
BEGIN
result := 42 / 0; -- "Unexpected" division by 0
RAISE custom_exception;
EXCEPTION -- Non-Compliant
WHEN custom_exception THEN
DBMS_OUTPUT.PUT_LINE ('custom_exception: ' || DBMS_UTILITY.FORMAT_ERROR_STACK);
END;
/
----
=== Compliant solution
2020-06-30 12:47:33 +02:00
2022-02-04 17:28:24 +01:00
[source,sql]
2020-06-30 12:47:33 +02:00
----
SET SERVEROUTPUT ON
DECLARE
result PLS_INTEGER;
custom_exception EXCEPTION;
BEGIN
result := 42 / 0; -- "Unexpected" division by 0
RAISE custom_exception;
EXCEPTION -- Compliant
WHEN custom_exception THEN
DBMS_OUTPUT.PUT_LINE ('custom_exception: ' || DBMS_UTILITY.FORMAT_ERROR_STACK);
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE ('other: ' || DBMS_UTILITY.FORMAT_ERROR_STACK);
END;
/
----
== Resources
* CWE - https://cwe.mitre.org/data/definitions/391[CWE-391 - Unchecked Error Condition]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Add a "WHEN OTHERS" clause.
=== Parameters
.excludeFunctions
****
----
false
----
'true' if functions should handle all exceptions, 'flase if they can let some propagate
****
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]