Re: Why doesn't `RAISE EXCEPTION` provide error context? - Mailing list pgsql-general

From David G. Johnston
Subject Re: Why doesn't `RAISE EXCEPTION` provide error context?
Date
Msg-id CAKFQuwYqx8N35iz31=4AsrjWWA8m3EBSrHEeizvL14gNUGSCMg@mail.gmail.com
Whole thread Raw
In response to Why doesn't `RAISE EXCEPTION` provide error context?  (Taytay <taylor@youneedabudget.com>)
Responses Re: Why doesn't `RAISE EXCEPTION` provide error context?  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-general
Adding "raw" content present on Nabble that gets filtered by the mailing list.

On Wednesday, April 1, 2015, Taytay <taylor@youneedabudget.com> wrote:
We make heavy use of `GET STACKED DIAGNOSTICS` to determine where errors
happened.
However, I am trying to use RAISE EXCEPTION to report errors, and have
discovered that RAISE is specifically prevented from adding to the error
context:

----
static void
plpgsql_exec_error_callback(void *arg)
{
        PLpgSQL_execstate *estate = (PLpgSQL_execstate *) arg;

        /* if we are doing RAISE, don't report its location */
        if (estate->err_text == raise_skip_msg)
                return;
----
 

So that means that this doesn't work:



 RAISE EXCEPTION 'This exception will not get a stack trace';

EXCEPTION WHEN others THEN

    -- If the exception we're catching is one that Postgres threw,
    -- like a divide by zero error, then this will get the full
    -- stack trace of the place where the exception was thrown.
    -- However, since we are catching an exception we raised manually
    -- using RAISE EXCEPTION, there is no context/stack trace!
    GET STACKED DIAGNOSTICS v_error_stack = PG_EXCEPTION_CONTEXT;


I've posted more details here:
http://dba.stackexchange.com/questions/96743/postgres-how-to-get-stack-trace-for-a-manually-raised-exception

That context would be awfully useful for us, even for manually generated
exceptions.
Can anyone shed some light on A) why this is, and B) if it's still desired,
and C) if so, are there any workarounds? Is there an exception I can trick
Postgres into throwing that will include my user-generated string?

Many thanks for any help you can offer.


 

pgsql-general by date:

Previous
From: Taytay
Date:
Subject: Why doesn't `RAISE EXCEPTION` provide error context?
Next
From: Pavel Stehule
Date:
Subject: Re: Why doesn't `RAISE EXCEPTION` provide error context?