Error handling in a stored procedure

mike55

Well-known member
Joined
Mar 26, 2004
Messages
726
Location
Ireland
Hi

Went looking for information on how to handle errors in SQL Server 2000. I originally thought it would be as simple as putting a try catch statement around my code, like for oracle, and then specifying what errors I want to check for. However, it seems that its not that simple for SQL Server 2000.

What one article said is that I must declare a variable as an integer.
Code:
Declare @err as int
Then after every statement, i check the value of my variable. If the value has changed, then an error has occured otherwise nothing.
Code:
Select @err = @@error
if @err <> 0
Return @err

My questions is whether this is the best way to handle exceptions in my stored procedure?

Mike55.
 
As far as I am aware its the only way to handle errors, though you can specify your own error messages to provide more or less information before returning out of the stored procedure.
 
Back
Top