Returns the last OLE2 exception signaled by a PL/SQL exception.
FUNCTION last_exception return NUMBER;
or
FUNCTION last_exception(message OUT VARCHAR2) return NUMBER;
message |
A text string (VARCHAR2) containing the text of the OLE2 error message. If included, this variable is returned to the caller of the function, in addition to the error code value. |
You can use either syntax for this function. The first syntax returns only the error code; the second syntax returns a text description of the error, in addition to the error code.
This function returns a complete OLE2 (Windows) style error code as a NUMBER. To extract just the error code portion, you must remove the highest bit (Severity) and then translate the remaining number to INTEGER or BINARY_INTEGER format.
PACKAGE olepack IS
PROCEDURE init(...);
PROCEDURE something(...);
PROCEDURE shutdown(...);
FUNCTION get_err(message OUT VARCHAR2) RETURN BINARY_INTEGER;
END olepack;
PACKAGE BODY olepack IS
...
FUNCTION get_err(message OUT VARCHAR2) RETURN BINARY_INTEGER IS
--
-- OLE errors are formatted as 32 bit unsigned integers and
-- returned as Oracle NUMBERS. We want to extract only the
-- error code, which is contained in the lowest 16 bits.
-- We must first strip off the top [severity] bit, if it
-- exists. Then, we must translate the error to an
-- INTEGER or BINARY INTEGER and extract the error code.
--
-- Some helpful constants:
-- 0x80000000 = 2147483648
-- 0x100000000 = 4294967296
-- 0x0000FFFF = 65535
--
hibit NUMBER := 2147483648;
four_gig NUMBER := 4294967296;
code_mask NUMBER := 65535;
excep NUMBER;
trunc_bi BINARY_INTEGER;
ole_code BINARY_INTEGER;
BEGIN
excep := OLE2.LAST_EXCEPTION(message);
IF (excep >= hibit) AND (excep <= four_gig) THEN
trunc_bi := excep - hibit;
END IF;
-- Mask out just the Code section
ole_code := BITAND(trunc_bi, code_mask);
RETURN ole_code;
END get_err;
END olepack;
PROCEDURE ole_test IS
err_code BINARY_INTEGER;
err_text VARCHAR2(255);
BEGIN
olepack.init(...);
olepack.something(...);
olepack.shutdown(...);
EXCEPTION
WHEN OLE2.OLE_ERROR THEN
err_code := olepack.get_err(err_text);
TEXT_IO.PUT_LINE('OLE Error #' || err_code || ': ' || err_text);
olepack.shutdown(...);
END ole_test;