Code Listing 2: The errpkg.raise procedure

1  PROCEDURE errpkg.raise (
 2     err_in IN INTEGER := SQLCODE, msg_in IN VARCHAR2 := NULL)
 3  IS
 4  BEGIN
 5     IF err_in BETWEEN -20999 AND -20000

 6     THEN
 7        RAISE_APPLICATION_ERROR (err_in, NVL (msg_in, errtext (err_in)));
 8
 9     ELSIF err_in > 0 AND err_in NOT IN (1, 100)
10     THEN
11        RAISE_APPLICATION_ERROR (-20000, err_in ||'-'||errtext (err_in));

12
13     ELSE
14        EXECUTE IMMEDIATE
15          'DECLARE myexc EXCEPTION; ' ||
16          '   PRAGMA EXCEPTION_INIT (myexc, ' ||
17                TO_CHAR (err_in) || ');' ||
18          'BEGIN  RAISE myexc; END;';

19     END IF;
20* END errpkg.raise;