Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Capturing fatal errors in SS2K

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-12-11 : 07:55:16
MM writes "Hi,

Please see the code block written below. Is there any way by which I can handle/trap the error that is generated when you execute this code block.

create table test (intCol int)

go
declare @ins_error int

begin tran

insert test (intCol)
select 'a'

select @ins_error = @@error

if @ins_error <> 0
begin
print 'error occurred'
rollback tran
end
else
begin
print 'no error'
commit tran
end

This code block seems to be generating a fatal error. Is there a way to trap such an error? I want to log all the errors that occur while executing my stored procedure, but when the above error is generated I'm not able to log it in a table.

Thanks."

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-12-11 : 08:04:36
you can use the raiserror() function or return the error code with an output paramterer.



Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page
   

- Advertisement -