exception

Started by hendra kusumaover 17 years ago2 messagesgeneral
Jump to latest
#1hendra kusuma
penguinroad@gmail.com

Dear all,

I'll have a little question here

I try to catch an exception as follows

CREATE OR REPLACE FUNCTION gruptambah(pnama character varying)
RETURNS integer AS
$BODY$
declare
ret integer;
begin
insert into grup (nama_grup, mulai_dibuat) values (pNama, now());
select last_value into ret from grup_id_seq;
return ret;
EXCEPTION
WHEN unique_violation THEN
RAISE NOTICE 'error';
return 0;
end;
$BODY$
LANGUAGE 'plpgsql';

it works perfectly
but I really like to ask if there is a way to catch any exeption
instead of defining what exception we would like to catch?
something like ELSE or what :)

Regards
Hendra

#2Klint Gore
kgore4@une.edu.au
In reply to: hendra kusuma (#1)
Re: exception

hendra kusuma wrote:

but I really like to ask if there is a way to catch any exeption
instead of defining what exception we would like to catch?
something like ELSE or what :)

From the manual

"The special condition name |OTHERS| matches every error type except
|QUERY_CANCELED|. "

klint.

--
Klint Gore
Database Manager
Sheep CRC
A.G.B.U.
University of New England
Armidale NSW 2350

Ph: 02 6773 3789
Fax: 02 6773 3266
EMail: kgore4@une.edu.au