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 2005 Forums
 Transact-SQL (2005)
 TRY CATCH

Author  Topic 

X002548
Not Just a Number

15586 Posts

Posted - 2008-04-22 : 21:55:23
Is it any better than using @@ERROR?

It doesn't seem so

Any opinions?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2008-04-22 : 22:38:30
depends on the scenerio. I prefer to use Try Catch when I want to ensure my remaining code does not continue to run when there is a error.
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2008-04-23 : 11:45:22
Yes, it is better.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2008-04-23 : 12:00:49
That's it?

Anything over severity level 20 still acts like previous versions

SELECT @error = @@error, @rowcount = @@rowcount

Then check for system or user error, and use goto to an error lable

so what's better?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2008-04-23 : 12:31:02
From BOL: Errors with severity of 20 or higher that terminate the SQL Server Database Engine task processing for the session. If an error occurs with severity of 20 or higher and the database connection is not disrupted, TRY…CATCH will handle the error.


So if you get a severity 20 or higher and the connection is disrupted I don't think it's going to matter how you are handling the error.
Go to Top of Page
   

- Advertisement -