File: README.exception_handling

package info (click to toggle)
firebird3.0 3.0.13.ds7-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 42,632 kB
  • sloc: ansic: 374,403; cpp: 319,973; sql: 14,691; pascal: 14,532; yacc: 7,557; fortran: 5,645; sh: 5,336; makefile: 1,041; perl: 194; sed: 83; awk: 76; xml: 19; csh: 15
file content (118 lines) | stat: -rw-r--r-- 2,832 bytes parent folder | download | duplicates (6)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
------------------
Exception handling
------------------

The common syntax rules for EXCEPTION statement is:

  EXCEPTION [[name] [value]];


Run-time exception messages (FB 1.5)
------------------------------------

  Function:
    Allows to throw exceptions with text message
    defined at runtime.

  Author:
    Dmitry Yemanov <yemanov@yandex.ru>

  Syntax rules:
    EXCEPTION <exception_name> <message_value>;

  Scope:
    PSQL

  Example(s):
    1. EXCEPTION E_EXCEPTION_1 'Error!';
    2. EXCEPTION E_EXCEPTION_2 'Wrong type for record with ID=' || new.ID;


Exception re-raise semantics (FB 1.5)
-------------------------------------

  Function:
    Allows to re-initiate catched exception.

  Author:
    Digitman <digitman@hotbox.ru>

  Syntax rules:
    EXCEPTION;

  Scope:
    PSQL, context of the exception handling block

  Example(s):
    BEGIN
      ...
    WHEN SQLCODE -802 DO
      EXCEPTION E_ARITH_EXCEPT;
    WHEN SQLCODE -802 DO
      EXCEPTION E_KEY_VIOLATION;
    WHEN ANY DO
      EXCEPTION;
    END

  Note(s):
    Evaluates to no-op if used outside the exception handling block.


Run-time error codes (FB 1.5)
-----------------------------

  Function:
    Allows to get a numeric error code for the catched exception.

  Author:
    Dmitry Yemanov <yemanov@yandex.ru>

  Syntax rules:
    SQLCODE / GDSCODE;

  Scope:
    PSQL, context of the exception handling block

  See also:
    README.context_variables


Parameterized exceptions (FB 3.0)
---------------------------------

  Function:
    Allow to define exception message with slots for parameters and pass the parameters when
    raising the exception.

  Author:
    Adriano dos Santos Fernandes <adrianosf at gmail.com>

  Syntax:
    EXCEPTION <name> USING ( <value list> )

  Example:
    create exception e_invalid_val 'Invalid value @1 for the field @2';

    ...
    if (val < 1000) then
       thing = val;
    else
       exception e_invalid_val using (val, 'thing');
    end

  Notes:
    The maximum number of arguments passed is 9.

    In the exception message, @NN (example: @10) is considered as @1 followed by the literal 0.

    The status vector is generated using these codes combination:
      isc_except, <exception number>,
      isc_formatted_exception, <formatted exception message>, <exception parameters>

    Since new error code (isc_formatted_exception) is used, it's necessary that the client is v3.0
    or at least uses firebird.msg from v3.0 so that it can translate the status vector to string.

    @N means the N parameter (where N starts at 1) passed in the exception raise command. If a N
    parameter is not passed, the text is not substituted. If NULL is passed, it's replaced by string
    '*** null ***'. If more parameters are passed than used in the exception message, they are
    ignored.