Ive follow procedure:
alter procedure sp_insert_cities
(
@txt_nome_cidade varchar(300),
@txt_nome_estado varchar(150) = null,
@txt_pais varchar(150) = null,
@int_id_cidade int output
)
as
begin
//Here an exception may occur
insert into tb_cidades values(
@txt_nome_cidade,
@txt_nome_estado,
@txt_pais)
set @int_id_cidade = @@identity
//Here i want to catch exception and continue executing the proc
if(@@error <> 0)
begin
select @int_id_cidade = int_id_cidade
from tb_cidades
where
txt_nome_cidade = @txt_nome_cidade
end
After if(@@error <> 0) line,i want to continue executing code even if there are any errors,but SQL throws an exception to my application and the code inside IF condition will not executed.
Any ideas?