rspec/rules/S1041/plsql/rule.adoc
Egon Okerman d1417e82f8
Modify CWE and OWASP Top 10 links to follow standard link format (APPSEC-1134) (#3529)
* Fix all CWE references

* Fix all OWASP references

* Fix missing CWE prefixes
2024-01-15 17:15:56 +01:00

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[]