Monday, March 5, 2007

Try ..Catch constructs

There are lots of companies,business have already upgraded to SQL Server 2005 ,definetly it makes sense because MS has introduced lots of new featuers. One of the many is how we can handle errors in SQL Server 2005


This procedure can be executed in your CATCH block.

CREATE PROCEDURE ErrorDetails
AS
SELECT
ERROR_NUMBER() AS ErrorNumber,
ERROR_SEVERITY() AS ErrorSeverity,
ERROR_STATE() AS ErrorState,
ERROR_PROCEDURE() AS ErrorProcedure,
ERROR_LINE() AS ErrorLine,
ERROR_MESSAGE() AS ErrorMessage;
GO


Connect to Object Explorer and execute the following code

BEGIN TRY
SELECT GETDATE()
SELECT 1/0
END TRY
BEGIN CATCH
SELECT ERROR_MESSAGE()
EXEC ErrorDetails
END CATCH;

Great thing that we can catch more errors by usig TRY ...CATCH block and what's more important to get an error message out.

2 comments:

haiyan said...

The Requiem shows up so many cool pictures that got me thinking a lot. And I really mean that a lot of requiem gold is very important and required. First off if the name is not taken the name and some requiem lant of book Requiem I do not if it is allowed to name a book. Some requiem money will well enough chatting better go and write this book. Comment on this please should I write this book or not. See you. In Requiem, there is blood. Monsters, blood, bigger monsters, and yes, more blood and need cheap requiem lant. You know what that requiem online gold means; there are factions, races changing sides, and all out war.

aiya said...
This comment has been removed by a blog administrator.