I need to pass the error to the application. I wrote the stored procedures as below: Does it pass the error to the application or we need to do the something more?
Eg.
create procedure insert_emp
as
begin try
begin tran
insert into emp values(..........)
commit;
end try
begin catch
if @@trancount > 0
rollback
declare @errMessage varchar(2000),
declare @errNumber int
select @errMessage = error_message(), @errNumber = error_number()
raiserror(@errMessage, @errNumber,1)
end catch
If I need to pass 0 if there is no error and a error number if there was a error, how to do it using raiserror? How can we log the error to error_table using raiserror? More importantly can above eg. pass the error to an application?