|
Posted by Erland Sommarskog on 05/27/05 00:01
Erland Sommarskog (esquel@sommarskog.se) writes:
> Steve (fizzy1236@yahoo.com) writes:
>> Thanks, I will give a good read through and rework this. Not too happy
>> with Microsoft's documentation, as they state I should be able to do
>> this. From Sql Server Books Online...
>>
>> -- Save any non-zero @@ERROR value.
>> IF (@@ERROR <> 0)
>> SET @ErrorSave = @@ERROR
>>
>> Found in the using @@ERROR section.
>
> See below for a link to an updated version of Books Online. It is indeed
> an embarrssing error. But the same section also says:
>
> Because @@ERROR is cleared and reset on each statement executed, check
> it immediately following the statement validated, or save it to a local
> variable that can be checked later.
By the way, while I don't want to embarrass you, I would like to point
out that this mishap could have been avoided if you had tested the
error handling, before you spread it all over town. Error-handling code
is one that is often over-looked when testing, but good testing should
also cover some error cases to see that they are handled well.
On a completely other note: SQL 2005 gives you exception handling with
TRY-CATCH syntax, which makes error handling in SQL 2005 a lot more
pleasant.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
Navigation:
[Reply to this message]
|