File tree Expand file tree Collapse file tree 1 file changed +67
-0
lines changed Expand file tree Collapse file tree 1 file changed +67
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+
3+ Automatically Detect Exception Handlers That ''Swallow Up'' Errors
4+
5+ Use compile time warnings to be warned if the compiler has identified an exception handler that does
6+ not contain a RAISE statement or a call to RAISE_APPLICATION_ERROR.
7+
8+ LiveSQL link: https://livesql.oracle.com/apex/livesql/file/content_C0VIPVWBK1FY057S1ZOOMKXE2.html
9+
10+ */
11+
12+ /* Force 6009 Warning as a Compile Error
13+
14+ Not only does this demonstrate a very cool feature of compile-time warnings (you can convert a warning into an error),
15+ but it also gets around a (current) limitation of LiveSQL: it is not yet displaying compile time warnings. Only
16+ compile failures. PLW-06009 warning is: "PLW-06009: procedure "string" OTHERS handler does not end in RAISE or
17+ RAISE_APPLICATION_ERROR" Cause: The OTHERS handler can exit without executing some form of RAISE or or a call
18+ to the standard procedure RAISE_APPLICATION_ERROR.
19+
20+ */
21+
22+ ALTER SESSION SET plsql_warnings = 'Error:6009'
23+ /
24+
25+ /* A RETURN is Not a Re-raise - FAIL! */
26+
27+ CREATE OR REPLACE FUNCTION plw6009
28+ RETURN VARCHAR2
29+ AS
30+ BEGIN
31+ RETURN 'abc';
32+ EXCEPTION
33+ WHEN OTHERS
34+ THEN
35+ RETURN 'abc';
36+ END plw6009;
37+ /
38+
39+ /* A Re-raise of the Current Exception - OK! */
40+
41+ CREATE OR REPLACE FUNCTION plw6009
42+ RETURN VARCHAR2
43+ AS
44+ BEGIN
45+ RETURN 'abc';
46+ EXCEPTION
47+ WHEN OTHERS
48+ THEN
49+ RAISE;
50+ END plw6009;
51+ /
52+
53+ /* Raise a New Error - OK! */
54+
55+ CREATE OR REPLACE FUNCTION plw6009
56+ RETURN VARCHAR2
57+ AS
58+ BEGIN
59+ RETURN 'abc';
60+ EXCEPTION
61+ WHEN OTHERS
62+ THEN
63+ RAISE_APPLICATION_ERROR (-20000, 'I am raising an exception!');
64+ END plw6009;
65+ /
66+
67+
You can’t perform that action at this time.
0 commit comments