83 lines
1.5 KiB
Plaintext
83 lines
1.5 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Ensure that every possible exception is caught by using a ``++WHEN OTHERS++`` clause.
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,sql]
|
|
----
|
|
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
|
|
|
|
[source,sql]
|
|
----
|
|
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[]
|