Skip to content

packages tree.raise_error

Jan Kvetina edited this page Oct 10, 2020 · 2 revisions

tree.raise_error

Repository spec: tree.raise_error, body: tree.raise_error

This function/procedure is used when you need to log error and raise application exception with in_action|log_id as name.
SQL%CODE defined in tree.app_exception_code is used.


Signature

PROCEDURE raise_error (
    in_action       logs.action_name%TYPE  := NULL,
    in_arg1         logs.arguments%TYPE     := NULL,
    in_arg2         logs.arguments%TYPE     := NULL,
    in_arg3         logs.arguments%TYPE     := NULL,
    in_arg4         logs.arguments%TYPE     := NULL,
    in_arg5         logs.arguments%TYPE     := NULL,
    in_arg6         logs.arguments%TYPE     := NULL,
    in_arg7         logs.arguments%TYPE     := NULL,
    in_arg8         logs.arguments%TYPE     := NULL
);
Show code (35 lines)

PROCEDURE raise_error (
    in_action       logs.action_name%TYPE   := NULL,
    in_arg1         logs.arguments%TYPE     := NULL,
    in_arg2         logs.arguments%TYPE     := NULL,
    in_arg3         logs.arguments%TYPE     := NULL,
    in_arg4         logs.arguments%TYPE     := NULL,
    in_arg5         logs.arguments%TYPE     := NULL,
    in_arg6         logs.arguments%TYPE     := NULL,
    in_arg7         logs.arguments%TYPE     := NULL,
    in_arg8         logs.arguments%TYPE     := NULL
) AS
    log_id          logs.log_id%TYPE;
    action_name     logs.action_name%TYPE;
BEGIN
    ROLLBACK;
    --
    action_name     := COALESCE(in_action, tree.get_caller_name(), 'UNEXPECTED_ERROR');
    log_id          := tree.log_error (
        in_action   => action_name,
        in_arg1     => in_arg1,
        in_arg2     => in_arg2,
        in_arg3     => in_arg3,
        in_arg4     => in_arg4,
        in_arg5     => in_arg5,
        in_arg6     => in_arg6,
        in_arg7     => in_arg7,
        in_arg8     => in_arg8
    );
    --
    --RAISE tree.app_exception;
    -- we could raise this^, but without custom message
    -- so we append same code but with message to current err_stack
    -- and we can intercept this code in calls above
    RAISE_APPLICATION_ERROR(tree.app_exception_code, action_name || tree.splitter || log_id, TRUE);
END;

Minimal example

PROCEDURE your_procedure AS
BEGIN
    tree.log_module();

    -- your code
    NULL;

    -- log error name/code with up to 8 arguments and raise exception
    tree.raise_error('ERROR_CODE');
END;

Intercept app exceptions to avoid stacking in log

PROCEDURE your_procedure AS
BEGIN
    tree.log_module();

    -- call code with raise_error inside
    BEGIN
        tree.log_module();
        tree.raise_error('ERROR_CODE');
    END;
EXCEPTION
WHEN tree.app_exception THEN  -- intercept app exception
    NULL;
    DBMS_OUTPUT.PUT_LINE('ALREADY STORED IN LOG');
END;

Clone this wiki locally