Hello,
the name of exception's variable I use as exception's name. Attached patch
work, but miss documentations, regress, ..
>BTW, is there any value in a separate "EXCEPTION" type? ISTM that an
>exception is just a SQLSTATE, which is in turn just a string. A separate
>exception type does simplify the parsing of RAISE, but I wonder if it
>would be useful to be able to also allow specifying the SQLSTATE code as
>a string literal.
Definition new attributes for exception isn't problem: level, errmsg.
Parsing raise stmt will be little bit more complicete. But why now?
CREATE OR REPLACE FUNCTION foo() RETURNS void AS $$
DECLARE my_own_exception EXCEPTION;
BEGIN
RAISE EXCEPTION my_own_exception 'some text';
END; $$ LANGUAGE plpgsql;
pokus=# select foo();
ERROR: some text
DETAIL: User's exception sqlstate: U0001, name: my_own_exception
HINT: Unhandled user's exception, from RAISE stmt on line 3
pokus=#
CREATE OR REPLACE FUNCTION foo() RETURNS void AS $$
DECLARE div_by_zero_test EXCEPTION = '22012';
BEGIN
RAISE EXCEPTION div_by_zero_test 'some text';
EXCEPTION WHEN division_by_zero THEN
RAISE NOTICE 'foo text';
END; $$ LANGUAGE plpgsql;
pokus=# select foo();
NOTICE: foo text
foo
-----
(1 row)
CREATE OR REPLACE FUNCTION foo() RETURNS void AS $$
DECLARE uexcpt01 EXCEPTION;
BEGIN
RAISE EXCEPTION uexcpt01 'aaaa';
EXCEPTION WHEN uexcpt01 THEN
RAISE NOTICE 'hello';
END; $$ LANGUAGE plpgsql;
pokus=# select foo();
NOTICE: hello
The patch isn't in production state (no from me:), but maybe is usefull
for test. The moust important is posibility handling own exception without
parsing SQLERRMS, I think. Setting SQLSTATE is usefull for
interoperatibility between procedures and throwing system errors.
Regards
Pavel Stehule