-
Notifications
You must be signed in to change notification settings - Fork 849
/
Copy pathno-reraise-no-exception.sql
90 lines (80 loc) · 2.43 KB
/
no-reraise-no-exception.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
You have a subprogram that invokes another subprogram (or nested block).
That "inner" subprogram fails with an exception. It contains an exception handler.
It logs the error, but then neglects to re-raise that exception (or another).
Control passes out to the invoking subprogram, and it continues executing statements,
completely unaware that an error occurred in that inner block. Which means,
by the way, that a call to SQLCODE will return 0. This may be just what
you want, but make sure you do this deliberately.
-- SQLCODE Outside of Exception Section Always 0
-- Because outside of an exception section, there is no exception. You are either declaring or executing.
BEGIN
DBMS_OUTPUT.put_line (SQLCODE);
END;
/
-- SQLCODE Invoked via Nested Subprogram from Exception Section
-- Just to avoid any misunderstanding: in this block, SQLCODE is "written"
-- outside of the exception section, but it is executed from within the OTHERS handler,
-- so SQLCODE will properly show the non-zero error code.
DECLARE
PROCEDURE my_proc
IS
BEGIN
DBMS_OUTPUT.put_line (
'Nested subprogram called from exception section SQLCODE='
|| SQLCODE);
END;
BEGIN
RAISE NO_DATA_FOUND;
EXCEPTION
WHEN OTHERS
THEN
my_proc;
END;
/
-- Watch the Changing SQLCODE Value
DECLARE
aname VARCHAR2 (5);
BEGIN
BEGIN
aname := 'Big String';
DBMS_OUTPUT.put_line (aname);
EXCEPTION
WHEN VALUE_ERROR
THEN
DBMS_OUTPUT.put_line (
'Inner block exception section SQLCODE='||SQLCODE);
END;
DBMS_OUTPUT.put_line ('In executable section SQLCODE='||SQLCODE);
EXCEPTION
WHEN VALUE_ERROR
THEN
DBMS_OUTPUT.put_line (
'Outer block exception section SQLCODE='||SQLCODE);
END;
/
ALTER SESSION SET plsql_warnings = 'enable:all' ;
CREATE OR REPLACE PROCEDURE swallow_error AUTHID DEFINER
IS
aname VARCHAR2 (5);
BEGIN
BEGIN
aname := 'Big';
DBMS_OUTPUT.put_line (aname);
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line (
'Inner block exception section SQLCODE='||SQLCODE);
END;
DBMS_OUTPUT.put_line ('In executable section SQLCODE='||SQLCODE);
EXCEPTION
WHEN VALUE_ERROR
THEN
DBMS_OUTPUT.put_line (
'Outer block exception section SQLCODE='||SQLCODE);
END;
/
SELECT text FROM USER_ERRORS
WHERE name = 'SWALLOW_ERROR'
/