61 lines
1.3 KiB
Plaintext
61 lines
1.3 KiB
Plaintext
Ensure that every possible exception is caught by using a ``++WHEN OTHERS++`` clause.
|
|
|
|
== Noncompliant Code Example
|
|
|
|
----
|
|
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
|
|
|
|
----
|
|
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;
|
|
/
|
|
----
|
|
|
|
include::../see.adoc[]
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::message.adoc[]
|
|
|
|
include::parameters.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::../comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|