You need a BEGIN ... EXCEPTION ... END
block.
create or replace function fun_testing(sn int, na text, gen text, ad text, rn int,
flag int)
returns int as
$$
begin
if flag = 1 then
insert into testing(ssn,name,gender,address,rno) values(sn,na,gen,ad,rn);
elsif flag = 2 then
update testing
set ssn=sn,
name=na,
gender=gen,
address=ad,
rno = rn
where ssn=sn;
elsif flag =3 then
delete from testing
where ssn =sn;
end if;
exception when others then
raise notice 'The transaction is in an uncommittable state. '
'Transaction was rolled back';
raise notice '% %', SQLERRM, SQLSTATE;
end;
$$ language 'plpgsql';